Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Commit

Permalink
Unit tests for DraftStringKey
Browse files Browse the repository at this point in the history
Summary: Simple unit tests for the DraftStringKey module

Reviewed By: j-nolan

Differential Revision: D15063748

fbshipit-source-id: f857332ed835cd3d79c2d68dc8ca133885d4a5ec
  • Loading branch information
Claudio Procida authored and facebook-github-bot committed Apr 25, 2019
1 parent 76e121e commit 978ad6b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/model/encoding/DraftStringKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
'use strict';

const DraftStringKey = {
stringify: function(key: mixed): string {
stringify: function(key: ?string): string {
return '_' + String(key);
},

Expand Down
25 changes: 25 additions & 0 deletions src/model/encoding/__tests__/DraftStringKey-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @emails oncall+draft_js
* @flow strict-local
* @format
*/

'use strict';

const {stringify, unstringify} = require('DraftStringKey');

test('must convert maybe strings to a string key', () => {
expect(stringify('anything')).toEqual('_anything');
expect(stringify(null)).toEqual('_null');
});

test('must convert string keys back to a string', () => {
expect(unstringify('_anything')).toEqual('anything');
// This is a lossy conversion
expect(unstringify('_null')).toEqual('null');
});

0 comments on commit 978ad6b

Please sign in to comment.