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

Commit 978ad6b

Browse files
Claudio Procidafacebook-github-bot
Claudio Procida
authored andcommitted
Unit tests for DraftStringKey
Summary: Simple unit tests for the DraftStringKey module Reviewed By: j-nolan Differential Revision: D15063748 fbshipit-source-id: f857332ed835cd3d79c2d68dc8ca133885d4a5ec
1 parent 76e121e commit 978ad6b

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/model/encoding/DraftStringKey.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
'use strict';
1313

1414
const DraftStringKey = {
15-
stringify: function(key: mixed): string {
15+
stringify: function(key: ?string): string {
1616
return '_' + String(key);
1717
},
1818

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @emails oncall+draft_js
8+
* @flow strict-local
9+
* @format
10+
*/
11+
12+
'use strict';
13+
14+
const {stringify, unstringify} = require('DraftStringKey');
15+
16+
test('must convert maybe strings to a string key', () => {
17+
expect(stringify('anything')).toEqual('_anything');
18+
expect(stringify(null)).toEqual('_null');
19+
});
20+
21+
test('must convert string keys back to a string', () => {
22+
expect(unstringify('_anything')).toEqual('anything');
23+
// This is a lossy conversion
24+
expect(unstringify('_null')).toEqual('null');
25+
});

0 commit comments

Comments
 (0)