forked from nodejs/nodejs.dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathonCreateNode.test.js
More file actions
36 lines (33 loc) · 1.07 KB
/
onCreateNode.test.js
File metadata and controls
36 lines (33 loc) · 1.07 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
import { onCreateNode } from '../../gatsby-node';
import createSlug from '../../src/util/createSlug';
jest.mock('../../src/util/createSlug', () => jest.fn(() => 'slug'));
function createMockNodeOfType(type) {
return {
actions: { createNodeField: jest.fn() },
getNode: jest.fn(),
node: {
internal: { type },
frontmatter: { title: 'Test title' },
},
};
}
describe('Tests for onCreateNode', () => {
beforeEach(() => {
createSlug.mockClear();
});
it('generates a slug for MarkdownRemark nodes', () => {
const { node, getNode, actions } = createMockNodeOfType('MarkdownRemark');
onCreateNode({ node, getNode, actions });
expect(createSlug).toHaveBeenCalledWith('Test title');
expect(actions.createNodeField).toHaveBeenCalledWith({
node,
name: 'slug',
value: 'slug',
});
});
it('only generates a slug for MarkdownRemark nodes', () => {
const { node, getNode, actions } = createMockNodeOfType('SomeOtherType');
onCreateNode({ node, getNode, actions });
expect(createSlug).not.toHaveBeenCalled();
});
});