Skip to content

Commit 83dbd76

Browse files
author
LB
authored
Merge pull request #902 from system-ui/add-options-tests
Add Jest setup for mocking Gatsby
2 parents 5aecd93 + 222602e commit 83dbd76

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

jest-preprocess.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = require('babel-jest').createTransformer({
2+
presets: ['babel-preset-gatsby'],
3+
})

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,10 @@
9696
],
9797
"setupFiles": [
9898
"jest-canvas-mock"
99-
]
99+
],
100+
"transform": {
101+
"^.+\\.jsx?$": "<rootDir>/jest-preprocess.js"
102+
}
100103
},
101104
"husky": {
102105
"hooks": {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const React = require('react')
2+
const gatsby = jest.requireActual('gatsby')
3+
4+
module.exports = {
5+
...gatsby,
6+
graphql: jest.fn(),
7+
useStaticQuery: jest.fn(() => ({
8+
themeUiConfig: {
9+
preset: {},
10+
},
11+
})),
12+
}

0 commit comments

Comments
 (0)