-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
93 lines (70 loc) · 2.64 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import { nl2br } from './index';
import React from 'react';
import assert from 'assert';
// I borrowed tests from here: https://github.com/yosuke-furukawa/react-nl2br
describe('nl2br', function () {
it('should return string #1', function () {
const result = nl2br('string');
const expected = 'string';
assert.deepEqual(expected, result);
});
it('should return string #2', function () {
const result = nl2br('test\nstring');
const expected = [
React.createElement(React.Fragment, { key: 0, children: 'test' }),
React.createElement('br', { key: '0br', }),
React.createElement(React.Fragment, { key: 1, children: 'string' })
];
assert.deepEqual(expected, result);
});
it('should return string #3', function () {
const result = nl2br('\ntest\n\nstring\n');
const expected = [
React.createElement('br', { key: '0br', }),
React.createElement(React.Fragment, { key: 1, children: 'test' }),
React.createElement('br', { key: '1br', }),
React.createElement('br', { key: '2br', }),
React.createElement(React.Fragment, { key: 3, children: 'string' }),
React.createElement('br', { key: '3br', }),
];
assert.deepEqual(expected, result);
});
it('should return string #4', function () {
const result = nl2br('\n\n');
const expected = [
React.createElement('br', { key: '0br' }),
React.createElement('br', { key: '1br' })
];
assert.deepEqual(expected, result);
});
it('should return number', function () {
const result = nl2br(13);
const expected = 13;
assert.deepEqual(expected, result);
});
it('should return undefined', function () {
const result = nl2br(undefined);
const expected = undefined;
assert.deepEqual(expected, result);
});
it('should return null', function () {
const result = nl2br(null);
const expected = null;
assert.deepEqual(expected, result);
});
it('should return array', function () {
const result = nl2br([]);
const expected = [];
assert.deepEqual(expected, result);
});
it('should return object', function () {
const result = nl2br({});
const expected = {};
assert.deepEqual(expected, result);
});
it('should return the given React component', function () {
const component = React.createElement('p', {}, 'Lorem ipsum');
const result = nl2br(component);
assert.strictEqual(component, result);
});
});