Skip to content

Commit

Permalink
Install & configure Jest, testing libs, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bennett Dams committed Oct 20, 2021
1 parent 78b657e commit aaf1fb3
Show file tree
Hide file tree
Showing 4 changed files with 5,983 additions and 1,742 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@
1. Install initial Create Next App with TypeScript
`npx create-next-app@latest --use-npm --ts .`

2. Create `src` folder at root and move `pages` folder to it
2. Create `src` folder at root and move `pages` folder to it

3. Install & configure Jest, testing libs, etc. based on [Next's docs](https://nextjs.org/docs/testing#jest-and-react-testing-library):
`npm install --save-dev jest babel-jest @testing-library/react @testing-library/jest-dom identity-obj-proxy react-test-renderer`
30 changes: 30 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module.exports = {
collectCoverageFrom: [
'**/*.{js,jsx,ts,tsx}',
'!**/*.d.ts',
'!**/node_modules/**',
],
moduleNameMapper: {
/* Handle CSS imports (with CSS modules)
https://jestjs.io/docs/webpack#mocking-css-modules */
'^.+\\.module\\.(css|sass|scss)$': 'identity-obj-proxy',

// Handle CSS imports (without CSS modules)
'^.+\\.(css|sass|scss)$': '<rootDir>/__mocks__/styleMock.js',

/* Handle image imports
https://jestjs.io/docs/webpack#handling-static-assets */
'^.+\\.(jpg|jpeg|png|gif|webp|svg)$': '<rootDir>/__mocks__/fileMock.js',
},
testPathIgnorePatterns: ['<rootDir>/node_modules/', '<rootDir>/.next/'],
testEnvironment: 'jsdom',
transform: {
/* Use babel-jest to transpile tests with the next/babel preset
https://jestjs.io/docs/configuration#transform-objectstring-pathtotransformer--pathtotransformer-object */
'^.+\\.(js|jsx|ts|tsx)$': ['babel-jest', { presets: ['next/babel'] }],
},
transformIgnorePatterns: [
'/node_modules/',
'^.+\\.module\\.(css|sass|scss)$',
],
}
Loading

0 comments on commit aaf1fb3

Please sign in to comment.