next/link legacyBehavior default value in tests incorrect as of v13 #42621
Labels
bug
Issue was opened via the bug report template.
Navigation
Related to Next.js linking (e.g., <Link>) and navigation.
Verify canary release
Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 21.6.0: Mon Aug 22 20:19:52 PDT 2022; root:xnu-8020.140.49~2/RELEASE_ARM64_T6000
Binaries:
Node: 16.13.2
npm: 8.1.2
Yarn: 3.1.1
pnpm: N/A
Relevant packages:
next: 13.0.2
eslint-config-next: 12.3.1
react: 18.2.0
react-dom: 18.2.0
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
Describe the Bug
After upgrading to v13 and replacing all our
next/link
to use the new syntax, we started to have some tests failing due to an error sayingReact.Children.only expected to receive a single React element child
.We are indeed passing multiple children to
<Link>
but it works fine in our app, just not in tests. After digging a bit, the error is thrown at this line. I noticed that this line is inside aif (legacyBehavior)
condition which doesn't make sense in our case as we are not using this prop.I therefore noticed that the default value of
legacyBehavior
isBoolean(process.env.__NEXT_NEW_LINK_BEHAVIOR) !== true
(here). After logging this env value, I saw it wasundefined
which explains whylegacyBehavior
ends up beingtrue
.Expected Behavior
As the new link behaviour is the default as of v13, I think this condition should be at least reversed or even removed so that the default behaviour is not the legacy one if
__NEXT_NEW_LINK_BEHAVIOR
is not set.Link to reproduction
https://github.com/ValentinH/next13-link-test-issue/blob/main/src/example.test.js
To Reproduce
Clone https://github.com/ValentinH/next13-link-test-issue and run
yarn test
.The text was updated successfully, but these errors were encountered: