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
|
import { frontMatterify, stringify } from '~/static_site_editor/services/front_matterify';
import {
sourceContentYAML as content,
sourceContentHeaderObjYAML as yamlFrontMatterObj,
sourceContentSpacing as spacing,
sourceContentBody as body,
} from '../mock_data';
describe('static_site_editor/services/front_matterify', () => {
const frontMatterifiedContent = {
source: content,
matter: yamlFrontMatterObj,
hasMatter: true,
spacing,
content: body,
delimiter: '---',
type: 'yaml',
};
const frontMatterifiedBody = {
source: body,
matter: null,
hasMatter: false,
spacing: null,
content: body,
delimiter: null,
type: null,
};
describe('frontMatterify', () => {
it.each`
frontMatterified | target
${frontMatterify(content)} | ${frontMatterifiedContent}
${frontMatterify(body)} | ${frontMatterifiedBody}
`('returns $target from $frontMatterified', ({ frontMatterified, target }) => {
expect(frontMatterified).toEqual(target);
});
it('should throw when matter is invalid', () => {
const invalidContent = `---\nkey: val\nkeyNoVal\n---\n${body}`;
expect(() => frontMatterify(invalidContent)).toThrow();
});
});
describe('stringify', () => {
it.each`
stringified | target
${stringify(frontMatterifiedContent)} | ${content}
${stringify(frontMatterifiedBody)} | ${body}
`('returns $target from $stringified', ({ stringified, target }) => {
expect(stringified).toBe(target);
});
});
});
|