next/jest does not render correctly with experimental.newNextLinkBehavior enabled #40463
Closed
1 task done
Labels
bug
Issue was opened via the bug report template.
Verify canary release
Provide environment information
Operating System:
Platform: darwin
Arch: x64
Version: Darwin Kernel Version 21.6.0: Wed Aug 10 14:25:27 PDT 2022; root:xnu-8020.141.5~2/RELEASE_X86_64
Binaries:
Node: 16.16.0
npm: 8.11.0
Yarn: 1.22.17
pnpm: N/A
Relevant packages:
next: 12.3.1-canary.0
eslint-config-next: N/A
react: 18.2.0
react-dom: 18.2.0
What browser are you using? (if relevant)
Not relevant (issue lies with
next/jest
)How are you deploying your application? (if relevant)
Not relevant (issue lies with
next/jest
)Describe the Bug
It seems that the experimental flag
newNextLinkBehavior
is not being respected bynext/jest
even when using the with-jest boilerplate example.The
next.config.js
file has been updated to include this flag:The issue in general seems to be that the flag is not being respected at all by Jest, and it is simply rendering using the legacy behavior of
<Link>
. It is evident when looking at the discrepancy between the rendered results of the same JSX template onindex.tsx
vs what is rendered by the inline snapshot when runningindex.test.tsx
:Failure to inherit additional props (e.g.
data-testid
)In
index.tsx
, using the following JSX template with render with the following result:However, running
index.test.tsx
with the same template will result in a different output:Notice that the
data-testid
fails to be rendered.Failure to render
<a>
in-placeThe JSX template used is:
Rendered by
index.tsx
:Inline snapshot rendered by
index.test.tsx
:Expected Behavior
It is expected that the Jest rendered output should match exactly as what is rendered by the dev server, i.e. it should respect the
newNextLinkBehavior
flag.For example, for this JSX template:
...should be rendered as the following when running Jest to generate an inline snapshot:
Link to reproduction
https://github.com/terrymun/nextjs-link-behavior-demo
To Reproduce
You can use the following JSX templates to verify that the dev render and what Jest renders are very different:
In order to verify/reproduce the bug, simply check out the repository and run jest using
yarn test
. Notice that the incorrectly generated inline snapshots actually pass the tests, and these snapshots do not match the rendered behavior when serving the site in dev mode (or building it).The text was updated successfully, but these errors were encountered: