Skip to content

Commit

Permalink
Integrate MSW with Jest
Browse files Browse the repository at this point in the history
  • Loading branch information
Bennett Dams committed Oct 20, 2021
1 parent cdd07c1 commit 3973836
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@

3. Install MSW and follow setup for mocks/handlers/server [via docs](https://nextjs.org/docs/testing#jest-and-react-testing-library):
`npm install msw --save-dev`

3. Integrate MSW with Jest
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = {
setupFilesAfterEnv: ['./jest.setup.js'],
collectCoverageFrom: [
'**/*.{js,jsx,ts,tsx}',
'!**/*.d.ts',
Expand Down
8 changes: 8 additions & 0 deletions jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { server } from './src/mocks/server.js'
// Establish API mocking before all tests.
beforeAll(() => server.listen())
// Reset any request handlers that we may add during the tests,
// so they don't affect other tests.
afterEach(() => server.resetHandlers())
// Clean up after the tests are finished.
afterAll(() => server.close())

0 comments on commit 3973836

Please sign in to comment.