Skip to content

Commit

Permalink
fix: jest test error when using Icon component
Browse files Browse the repository at this point in the history
  • Loading branch information
tonible14012002 committed Sep 28, 2023
1 parent d564a07 commit ebf635b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"createDefaultProgram": true
},
"rules": {},
"ignorePatterns": ["__mocks__/"],
"overrides": [
{
"files": ["**/*.ts?(x)", "**/*.js?(x)"],
Expand Down
7 changes: 7 additions & 0 deletions __mocks__/svgrMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { forwardRef } from 'react'

const SvgrMock = forwardRef((props, ref) => <span ref={ref} {...props} />)

export const ReactComponent = SvgrMock

export default SvgrMock
16 changes: 14 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,17 @@ const customJestConfig = {
coverageProvider: 'v8',
}

// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
module.exports = createJestConfig(customJestConfig)
const jestConfig = async () => {
const nextJestConfig = await createJestConfig(customJestConfig)()

return {
...nextJestConfig,
moduleNameMapper: {
'\\.svg': '<rootDir>/__mocks__/svgrMock.js',
// Workaround to put our SVG mock first
...nextJestConfig.moduleNameMapper,
},
}
}

module.exports = jestConfig

0 comments on commit ebf635b

Please sign in to comment.