-
-
Notifications
You must be signed in to change notification settings - Fork 435
/
Copy pathdom.test.ts
52 lines (47 loc) · 1.57 KB
/
dom.test.ts
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
import { splitByBoldTag } from '../../browser/utils/dom';
import { expect } from 'chai';
describe('dom', () => {
describe('splitByBoldTag', () => {
it('should split by bold tags', () => {
const actual = splitByBoldTag('one<b>matchOne</b>two');
const expected = ['one', { textContent: 'matchOne', bold: true }, 'two'];
expect(actual).to.be.deep.equal(expected);
});
it('should handle starting bold tags', () => {
const actual = splitByBoldTag(
'<b>matchOne</b>one<b>matchTwo</b> two <b>matchThree</b> three'
);
const expected = [
{ textContent: 'matchOne', bold: true },
'one',
{ textContent: 'matchTwo', bold: true },
' two ',
{ textContent: 'matchThree', bold: true },
' three',
];
expect(actual).to.be.deep.equal(expected);
});
it('should handle unclosed bold tags', () => {
const actual = splitByBoldTag(
'<b>matchOne</b>one<b>matchTwo</b> two <b>matchThree</b> three <b> '
);
const expected = [
{ textContent: 'matchOne', bold: true },
'one',
{ textContent: 'matchTwo', bold: true },
' two ',
{ textContent: 'matchThree', bold: true },
' three <b> ',
];
expect(actual).to.be.deep.equal(expected);
});
it('should handle no matches', () => {
const actual = splitByBoldTag('<b>alma');
expect(actual).to.be.undefined;
});
it('should handle empty strings', () => {
const actual = splitByBoldTag('');
expect(actual).to.be.undefined;
});
});
});