question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`data-testid` being stripped in test/local env in latest 12.1.6

See original GitHub issue

Verify canary release

  • I verified that the issue exists in Next.js canary release

Provide environment information

Operating System: Platform: linux Arch: x64 Version: #1 SMP Wed Mar 2 00:30:59 UTC 2022 Binaries: Node: 14.18.1 npm: 6.14.15 Yarn: 1.22.18 pnpm: N/A Relevant packages: next: 12.1.6 react: 18.1.0 react-dom: 18.1.0

What browser are you using? (if relevant)

Firefox

How are you deploying your application? (if relevant)

Vercel

Describe the Bug

In the latest 12.1.6, running Jest locally with tests that try to locate elements using the data-testid attr fail, this works fine in 12.1.5.

In my next config I have:

compiler: {
    styledComponents: true,
    reactRemoveProperties: true,
  },

image

Expected Behavior

data-testid should only be removed in production env, not local or preview envs.

To Reproduce

Create a projec with latest next, jest, and a test that looks for a data-testid.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:4
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
SukkaWcommented, May 15, 2022

The issue should be fixed by https://github.com/vercel/next.js/pull/36922

In the meantime, you can apply a temporary fix in your next.config.js:

// next.config.js
module.exports = {
  compiler: {
-   reactRemoveProperties: true
+   reactRemoveProperties: process.env.NODE_ENV === 'production'
  }
}
2reactions
timneutkenscommented, May 6, 2022

This is because next/jest previously did not apply the opt-in transforms and that was fixed. I guess for reactRemoveProperties we’ll want to disable that in the test env when the true option is used.

Read more comments on GitHub >

github_iconTop Results From Across the Web

babel-plugin-jsx-remove-data-test-id
babel plugin to remove data-test-id attributes. Latest version: 3.0.0, last published: 2 years ago.
Read more >
testcafe | Yarn - Package Manager
A Node.js tool to automate end-to-end web testing.
Read more >
Untitled
Paris torosidis tennis, Pre anesthesia testing, Optica planeta vision, Einhell hebezug, ... New balloon designs, Traktory dojc, Local weather 76401, ...
Read more >
Search Results - CVE
The mission of the CVE® Program is to identify, define, and catalog publicly disclosed cybersecurity vulnerabilities.
Read more >
Lead acetate | C4H6O4Pb - PubChem - NIH
National Toxicology Program, Institute of Environmental Health Sciences, ... Hazardous Substances Data Bank (HSDB); ILO International Chemical Safety Cards ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found