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.

setupTests.js does not work in src/ path

See original GitHub issue

I’m working with some simple tests. My project was made with Create React App. I have everything in a separeted folder src/tests. Everything was working fine but with just one file. When I wanted to add a new test file, I wanted to have in a single file the adapter configuration to not boilerplate the code. I added a setupTests.js to the src path and I ran the test again, but this time didn’t work, throwing me the Enzyme message about the adapter. The configuration is the next and it works fine if I add it to each file. I installed everything using npm but later I had to use yarn to resolve some dependencies issues.

  • setupTests.js
import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';

configure({ adapter: new Adapter() });

I’ve seen that some people added:

{
  "jest": {
    "setupTestFrameworkScriptFile": "<rootDir>/path/to/your/file.js",
  }
}

but it didn’t work for me and I think is not a good practice to ovewrite the setup file like this way.

Environment

  1. node -v: v8.9.4
  2. npm -v: 5.8.0
  3. yarn --version (if you use Yarn): 1.5.1
  4. npm ls react-scripts (if you haven’t ejected): No
  5. Operating system: Windows 10

This is the link of my tests: https://github.com/DracotMolver/React-Practicing/tree/master/DragAndDrop/src/tests

By now I have the Enzyme adapter configuration on each file. Any help I’ll be thankful.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
ykravvcommented, Mar 25, 2018

setupTests.js should be placed in src folder. I don’t see it in your example

Read more comments on GitHub >

github_iconTop Results From Across the Web

Enzyme can't find setupTests file for React app when using ...
(src/tests/HomePage.test.js:3:1). It looks like my path to the setupTests.js file is wrong but how could it work locally?
Read more >
Set Up Jest and React Testing Library for Unit Testing
Create a file to put all the logic that should run before running the test. It is usually called setupTests.js, and the code...
Read more >
Running Tests | Create React App
Jest is a Node-based runner. This means that the tests always run in a Node environment and not in a real browser. This...
Read more >
Configuring Vitest
If you want to have a different configuration for testing or your main app doesn't rely on Vite specifically, you could either: Create...
Read more >
Configuring Jest
If the file specified by path is not found, an error is returned. For example, with the following configuration: JavaScript; TypeScript. /** @ ......
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