Skip to content

Commit

Permalink
Add Jest testing skeleton and one snapshot test (#613)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonbcox authored Sep 23, 2020
1 parent 4e0b3e2 commit 38e5dbf
Show file tree
Hide file tree
Showing 10 changed files with 4,956 additions and 238 deletions.
1 change: 1 addition & 0 deletions v2/__mocks__/file-mock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = "test-file-stub"
26 changes: 26 additions & 0 deletions v2/__mocks__/gatsby.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const React = require("react")
const gatsby = jest.requireActual("gatsby")

module.exports = {
...gatsby,
graphql: jest.fn(),
Link: jest.fn().mockImplementation(
({
activeClassName,
activeStyle,
getProps,
innerRef,
partiallyActive,
ref,
replace,
to,
...rest
}) =>
React.createElement("a", {
...rest,
href: to,
})
),
StaticQuery: jest.fn(),
useStaticQuery: jest.fn(),
}
5 changes: 5 additions & 0 deletions v2/__mocks__/i18n/provider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
useLocaleContext: jest.fn(() => ({
slug: "",
})),
}
13 changes: 13 additions & 0 deletions v2/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
moduleNameMapper: {
".+\\.(css|styl|less|sass|scss)$": `identity-obj-proxy`,
".+\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": `<rootDir>/__mocks__/file-mock.js`,
},
testPathIgnorePatterns: [`node_modules`, `\\.cache`, `<rootDir>.*/public`],
transformIgnorePatterns: [`node_modules/(?!(gatsby)/)`],
globals: {
__PATH_PREFIX__: ``,
},
testURL: `http://localhost`,
setupFiles: [`<rootDir>/jest/loadershim.js`],
}
3 changes: 3 additions & 0 deletions v2/jest/loadershim.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
global.___loader = {
enqueue: jest.fn(),
}
Loading

0 comments on commit 38e5dbf

Please sign in to comment.