-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.test.js
49 lines (41 loc) · 1.17 KB
/
index.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
const frontMatterLoader = require('.');
const source = `---
title: Example
description: This is an example
---
Here is some example content`;
test('extracts frontmatter and body as an object', () => {
const context = {
cacheable: jest.fn(),
getOptions: () => ({}),
};
expect(frontMatterLoader.call(context, source)).toBe(
'{' +
'"attributes":{' +
'"title":"Example",' +
'"description":"This is an example"' +
'},' +
'"body":"Here is some example content",' +
'"bodyBegin":6,' +
'"frontmatter":"title: Example\\ndescription: This is an example"' +
'}'
);
});
test('extracts only the frontmatter when onlyAttributes is passed', () => {
const context = {
cacheable: jest.fn(),
getOptions: () => ({ onlyAttributes: true }),
};
expect(frontMatterLoader.call(context, source)).toBe(
'{"title":"Example","description":"This is an example"}'
);
});
test('extracts only the body when onlyBody is passed', () => {
const context = {
cacheable: jest.fn(),
getOptions: () => ({ onlyBody: true }),
};
expect(frontMatterLoader.call(context, source)).toBe(
'Here is some example content'
);
});