-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathfile-writers.test.js
More file actions
39 lines (30 loc) · 1.02 KB
/
file-writers.test.js
File metadata and controls
39 lines (30 loc) · 1.02 KB
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
const util = require('util');
const mockPromisifiedFunction = jest.fn();
util.promisify = jest.fn(() => mockPromisifiedFunction);
jest.mock('fs');
const fileWriters = require('./file-writers');
afterEach(() => {
jest.clearAllMocks();
});
describe('`writeFrontmatterMarkdown()`', () => {
test('writes Markdown files with frontmatter', () => {
const mockContent = {
body: 'This is the body',
frontmatter: {
name: 'John Doe'
}
};
const content = fileWriters.writeFrontmatterMarkdown(mockContent);
expect(content).toBe(`---\nname: ${mockContent.frontmatter.name}\n---\n${mockContent.body}\n`);
});
test('converts body to string', () => {
const mockContent = {
body: [1, 2, 3],
frontmatter: {
name: 'John Doe'
}
};
const content = fileWriters.writeFrontmatterMarkdown(mockContent);
expect(content).toBe('---\nname: John Doe\n---\n1,2,3\n');
});
});