Skip to content

Commit c7fd8ff

Browse files
committed
test: add test for TranslatorCollection
1 parent b9e30b0 commit c7fd8ff

File tree

2 files changed

+53
-9
lines changed

2 files changed

+53
-9
lines changed

test/e2e.test.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ import { NodeHtmlMarkdown } from '../src';
22
import { DOMParser } from 'linkedom';
33

44

5-
const html = `<html><body><p><b>F</b><span>oo</span></p><ul><li>Bar</li></ul></body></html>`
5+
const html = `<html><body><p><b>F</b><span>oo</span></p><ul><li>Bar</li></ul></body></html>`;
66

7-
test('Browser', () => {
8-
__IS_BROWSER__ = true
9-
globalThis.DOMParser = <typeof globalThis.DOMParser>DOMParser
10-
const res = new NodeHtmlMarkdown({
11-
preferNativeParser: true
12-
}).translate(html);
13-
expect(res).toBe(`**F**oo\n\n* Bar`);
14-
})
7+
describe('E2E', () => {
8+
test('Browser', () => {
9+
__IS_BROWSER__ = true;
10+
globalThis.DOMParser = <typeof globalThis.DOMParser>DOMParser;
11+
const res = new NodeHtmlMarkdown({
12+
preferNativeParser: true
13+
}).translate(html);
14+
expect(res).toBe(`**F**oo\n\n* Bar`);
15+
});
16+
});

test/translator-collection.test.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { TranslatorCollection, TranslatorConfigFactory } from '../src';
2+
3+
4+
describe('TranslatorCollection', () => {
5+
let collection: TranslatorCollection;
6+
beforeEach(() => {
7+
collection = new TranslatorCollection();
8+
collection.set('p', { ignore: true });
9+
});
10+
test('size', () =>
11+
expect(collection.size).toBe(1)
12+
);
13+
test('get', () => {
14+
expect(collection.get('p')).toEqual({ ignore: true });
15+
expect(collection.get('P')).toEqual({ ignore: true });
16+
expect(collection['P']).toEqual({ ignore: true });
17+
});
18+
test('set', () => {
19+
collection.set('p', { ignore: false });
20+
expect(collection.get('p')).toEqual({ ignore: false });
21+
});
22+
test('set with preserveBase', () => {
23+
collection.set('p', { recurse: true }, true);
24+
expect(collection.get('p')).toEqual({ ignore: true, recurse: true });
25+
});
26+
test('set with preserveBase and configFactory', () => {
27+
collection.set('p', () => ({ recurse: true }), true);
28+
expect(collection.get('p')).toBeInstanceOf(Function)
29+
expect((<Function>collection.get('p'))()).toEqual({ recurse: true });
30+
expect((<TranslatorConfigFactory>collection.get('p')).base).toEqual({ ignore: true });
31+
});
32+
test('set with multiple keys', () => {
33+
collection.set('p,div', { ignore: false });
34+
expect(collection.get('p')).toEqual({ ignore: false });
35+
expect(collection.get('div')).toEqual({ ignore: false });
36+
});
37+
test('entries', () => expect(collection.entries()).toEqual([ [ 'P', { ignore: true } ] ]));
38+
test('remove', () => {
39+
collection.remove('p');
40+
expect(collection.get('p')).toBeUndefined();
41+
});
42+
});

0 commit comments

Comments
 (0)