Skip to content

Commit

Permalink
Add test for transformer-remark
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleAMathews committed Apr 18, 2017
1 parent e849351 commit 1f1d870
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Process markdown content correctly Correctly creates a new MarkdownRemark node 1`] = `
Array [
Array [
Object {
"children": Array [],
"content": "
Where oh where is my little pony?
",
"contentDigest": "54cfa2ad99756f2fa232cac585280a37",
"frontmatter": Object {
"date": "12/12/2014",
"parent": "whatever",
"title": "my little pony",
},
"id": "whatever >>> MarkdownRemark",
"mediaType": "text/x-markdown",
"parent": "whatever",
"type": "MarkdownRemark",
},
],
]
`;

exports[`Process markdown content correctly Correctly creates a new MarkdownRemark node 2`] = `
Array [
Array [
Object {
"children": Array [
"whatever >>> MarkdownRemark",
],
"content": "---
title: \\"my little pony\\"
date: \\"12/12/2014\\"
---
Where oh where is my little pony?
",
"contentDigest": "whatever",
"id": "whatever",
"mediaType": "text/x-markdown",
},
],
]
`;
43 changes: 43 additions & 0 deletions packages/gatsby-transformer-remark/__tests__/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const Promise = require("bluebird")

const { onNodeCreate } = require("../src/gatsby-node")

describe(`Process markdown content correctly`, () => {
const node = {
id: "whatever",
contentDigest: "whatever",
mediaType: `text/x-markdown`,
children: [],
}

// Make some fake functions its expecting.
const loadNodeContent = node => {
return Promise.resolve(node.content)
}

it(`Correctly creates a new MarkdownRemark node`, async () => {
const content = `---
title: "my little pony"
date: "12/12/2014"
---
Where oh where is my little pony?
`
node.content = content

const createNode = jest.fn()
const updateNode = jest.fn()
const boundActionCreators = { createNode, updateNode }

await onNodeCreate({
node,
loadNodeContent,
boundActionCreators,
}).then(() => {
expect(createNode.mock.calls).toMatchSnapshot()
expect(updateNode.mock.calls).toMatchSnapshot()
expect(createNode).toHaveBeenCalledTimes(1)
expect(updateNode).toHaveBeenCalledTimes(1)
})
})
})

0 comments on commit 1f1d870

Please sign in to comment.