Skip to content

Commit

Permalink
Merge pull request #1 from mnrendra/unit-test
Browse files Browse the repository at this point in the history
Setup test libraries and initiate unit-test example.
  • Loading branch information
mnrendra authored Nov 22, 2022
2 parents 91934a3 + df40322 commit a464f51
Show file tree
Hide file tree
Showing 6 changed files with 11,518 additions and 4,076 deletions.
38 changes: 38 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// jest.config.js
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
/** @type {import('jest').Config} */
const customJestConfig = {
// Add more setup options before each test is run
// setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
// if using TypeScript with a baseUrl set to the root directory then you need the below for alias' to work
moduleDirectories: ['node_modules', '<rootDir>/'],
moduleNameMapper: {
// style
"^@styles/(.*)": "<rootDir>/styles/$1",
// ui
"^@ui": "<rootDir>/ui",
"^@ui/(.*)": "<rootDir>/ui/$1",
// components
"^@components": "<rootDir>/components",
"^@components/(.*)": "<rootDir>/components/$1",
// utils
"^@utils": "<rootDir>/utils",
"^@utils/(.*)": "<rootDir>/utils/$1",
// store
"^@store": "<rootDir>/store",
"^@store/(.*)": "<rootDir>/store/$1",
},
testEnvironment: 'jest-environment-jsdom',
// load `jest.setup.js` to load `import '@testing-library/jest-dom'`
setupFilesAfterEnv: ['<rootDir>/jest.setup.js']
}

// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
module.exports = createJestConfig(customJestConfig)
5 changes: 5 additions & 0 deletions jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// jest-dom adds custom jest matchers for asserting on DOM nodes.
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom'
Loading

1 comment on commit a464f51

@vercel
Copy link

@vercel vercel bot commented on a464f51 Nov 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.