Skip to content

Commit

Permalink
feat(root): added Jest framework for testing
Browse files Browse the repository at this point in the history
Added jest jest-environment-jsdom @testing-library/react @testing-library/jest-dom and a basic
configuration to run jest tests.

#21
  • Loading branch information
McGeerDev committed Jan 29, 2023
1 parent 6f1e1e3 commit 40d9997
Show file tree
Hide file tree
Showing 3 changed files with 1,999 additions and 40 deletions.
25 changes: 25 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// jest.config.js

// Since the release of Next.js 12,
// Next.js now has built -in configuration for Jest.
const nextJest = require('next/jest')

const createJestConfig = nextJest({
// Provide the path to your Next.js app to load next.config.js and .env files in your test environment
dir: './',
})

// Add any custom config to be passed to Jest
const customJestConfig = {
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
moduleNameMapper: {
// Handle module aliases (this will be automatically configured for you soon)
'^@/components/(.*)$': '<rootDir>/components/$1',

'^@/pages/(.*)$': '<rootDir>/pages/$1',
},
testEnvironment: 'jest-environment-jsdom',
}

// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
module.exports = createJestConfig(customJestConfig)
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"start": "next start",
"lint": "next lint",
"lint:fix": "next lint --fix",
"test": "jest --watch",
"test:ci": "jest --ci",
"prepare": "husky install"
},
"dependencies": {
Expand All @@ -25,6 +27,8 @@
"@commitlint/cli": "17.4.2",
"@commitlint/config-conventional": "17.4.2",
"@next/eslint-plugin-next": "13.1.4",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@types/howler": "2.2.7",
"@types/react": "18.0.27",
"@typescript-eslint/eslint-plugin": "5.48.2",
Expand All @@ -43,6 +47,8 @@
"eslint-plugin-promise": "6.1.1",
"eslint-plugin-react": "7.32.1",
"husky": "8.0.3",
"jest": "^29.4.1",
"jest-environment-jsdom": "^29.4.1",
"postcss": "8.4.21",
"prettier": "2.8.3",
"tailwind-styled-components": "2.2.0",
Expand Down
Loading

0 comments on commit 40d9997

Please sign in to comment.