Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make esm default interpolation work with jest mock
- Loading branch information
1 parent
092346d
commit 0aa484a
Showing
3 changed files
with
41 additions
and
1 deletion.
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,14 @@ | ||
import React from 'react' | ||
import { renderToString } from 'react-dom/server' | ||
import * as nextRouter from 'next/router' | ||
|
||
import { Foo } from './fixture' | ||
|
||
// @ts-expect-error | ||
jest.spyOn(nextRouter, 'useRouter').mockReturnValue({ | ||
pathname: 'Hello', | ||
}) | ||
|
||
test('mock the interpolated modules should work', () => { | ||
expect(() => renderToString(<Foo />)).not.toThrow() | ||
}) |
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,8 @@ | ||
import React from 'react' | ||
import { useRouter } from 'next/router' | ||
|
||
export const Foo = () => { | ||
const router = useRouter() | ||
|
||
return <div>{router.pathname}</div> | ||
} |