-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcobalt-markdown.test.js
46 lines (39 loc) · 1.6 KB
/
cobalt-markdown.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
const {
parseCobaltMarkdown,
generateCobaltMarkdown
} = require('./cobalt-markdown');
describe('cobalt-markdown parsing', () => {
const exampleContent = `{"test": true}\n---\n\n# Some test content here\nMaybe some more`;
const brokenContentSeparator = `{"test": true}\n--\n\n# Some test content here\nMaybe some more`;
const brokenContentMeta = `{"invalid json"}\n---\n\n# Some test content here\nMaybe some more`;
// Parse example content
it('should parse example content', () => {
expect(parseCobaltMarkdown(exampleContent)).toEqual({
meta: { test: true },
content: '# Some test content here\nMaybe some more'
});
});
// Not parse invalid content
it('should not parse invalid content', () => {
expect(() => parseCobaltMarkdown(brokenContentSeparator)).toThrow();
expect(() => parseCobaltMarkdown(brokenContentMeta)).toThrow();
});
});
describe('cobalt-markdown generation', () => {
const validMeta = { someValidMeta: true };
const invalidMeta = { invalid: true, becauseOfThis: () => {} };
const content = '# Some test content here\nMaybe some more';
it('should generate readable COMD', () => {
expect(generateCobaltMarkdown(validMeta, content, true)).toBe(
'{\n "someValidMeta": true\n}\n---\n\n# Some test content here\nMaybe some more\n'
);
});
it('should generate COMD', () => {
expect(generateCobaltMarkdown(validMeta, content)).toBe(
'{"someValidMeta":true}\n---\n# Some test content here\nMaybe some more'
);
});
it('should not generate COMD', () => {
expect(() => parseCobaltMarkdown(invalidMeta, content)).toThrow();
});
});