I want to make tests of my create-react-app using jest.
One of node_modules have test-error,
but I don't want jest to work with node_modules folder.
In the documentation I found configuration property "collectCoverageFrom" and tried to use itin my package.json:
....
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom ",
"eject": "react-scripts eject"
},
"jest": {
"collectCoverageFrom": [
"!/node_modules/*"
]
}
But there is nothing changed.
I want to make tests of my create-react-app using jest.
One of node_modules have test-error,
but I don't want jest to work with node_modules folder.
In the documentation I found configuration property "collectCoverageFrom" and tried to use itin my package.json:
....
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom ",
"eject": "react-scripts eject"
},
"jest": {
"collectCoverageFrom": [
"!/node_modules/*"
]
}
But there is nothing changed.
Share Improve this question edited Nov 8, 2018 at 16:06 skyboyer 23.8k7 gold badges62 silver badges71 bronze badges asked Dec 26, 2017 at 12:36 Alexander KnyazevAlexander Knyazev 2,8924 gold badges18 silver badges27 bronze badges 6- testpathignorepatterns. – Andy Commented Dec 26, 2017 at 12:39
- @Andy Out of the box, Create React App only supports overriding these Jest options: • collectCoverageFrom • coverageReporters • coverageThreshold • snapshotSerializers. – Alexander Knyazev Commented Dec 26, 2017 at 12:43
-
Then I'm surprised it's not ignoring your
node_modules
folder. – Andy Commented Dec 26, 2017 at 12:47 - Oh, it is ignoring your modules folder, but your test relies on something that's not working properly. That's a different problem. – Andy Commented Dec 26, 2017 at 12:49
- It works by node_module and I don't want jest to analyse it( – Alexander Knyazev Commented Dec 26, 2017 at 12:56
3 Answers
Reset to default 2There is nothing with coverage.
One of your ponents is using react-mic
package provides access to audio through window.AudioContext
.
You have different ways to solve it.
You may mock
window.AudioContext
. It would be really hard to achieve. I don't really suggest you doing that.You can mock
react-mic
module. That's much more achievable than #1 but still quite hard.You can rely on
shallow()
in your tests. So your will never need to mock anything related to Audio at all. I'd like to suggest you doing that way.
It's like that already. Jest ignores node_modules
. What you see is just a stack trace. Double check your tests code, something wrong is happening there.
Try using testPathIgnorePatterns
when configuring jest:
"jest": {
...
"testPathIgnorePatterns": [
"<rootDir>/(build|docs|node_modules)/"
]
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745357450a4624205.html
评论列表(0条)