-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: add Jest and React testing library
- Loading branch information
Showing
6 changed files
with
11,002 additions
and
4,662 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
|
||
import About from '@/pages/about'; | ||
|
||
// The easiest solution to mock `next/router`: https://github.com/vercel/next.js/issues/7479 | ||
jest.mock('next/router', () => ({ | ||
useRouter() { | ||
return { | ||
basePath: '.', | ||
}; | ||
}, | ||
})); | ||
|
||
describe('About page', () => { | ||
it('should render the About page', () => { | ||
render(<About />); | ||
|
||
const paragraph = screen.getAllByText(/Lorem ipsum/i); | ||
|
||
expect(paragraph.length).toEqual(2); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
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: './', | ||
}); | ||
|
||
const customJestConfig = { | ||
setupFilesAfterEnv: ['./jest.setup.js'], | ||
moduleNameMapper: { | ||
// Handle module aliases (this will be automatically configured for you soon) | ||
'^@/(.*)$': '<rootDir>/src/$1', | ||
|
||
'^@/public/(.*)$': '<rootDir>/public/$1', | ||
}, | ||
testEnvironment: 'jest-environment-jsdom', | ||
}; | ||
|
||
module.exports = createJestConfig(customJestConfig); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import '@testing-library/jest-dom/extend-expect'; |
Oops, something went wrong.