forked from vercel/next.js
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable jest hoist transform when using next/jest
Fixes vercel#32539 Implements what was shared at vercel#32539 (comment).
- Loading branch information
1 parent
0d642f1
commit 4d36b46
Showing
2 changed files
with
32 additions
and
0 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,24 @@ | ||
// home.test.js | ||
import router from 'next/router' | ||
// const router = require('next/router') | ||
// jest.setup.js | ||
jest.mock('next/router', () => ({ | ||
push: jest.fn(), | ||
back: jest.fn(), | ||
events: { | ||
on: jest.fn(), | ||
off: jest.fn(), | ||
}, | ||
asPath: jest.fn().mockReturnThis(), | ||
beforePopState: jest.fn(() => null), | ||
useRouter: () => ({ | ||
push: jest.fn(), | ||
}), | ||
})) | ||
|
||
describe(`Page / Home`, () => { | ||
it(`call mocked`, async () => { | ||
console.log(router) | ||
expect(typeof router.useRouter).toBe('function') // mocked | ||
}) | ||
}) |