I need to setup jest and JavaScript Standard Style to work together when using npm test
.
Now when I am running npm test
the test fails because JavaScript Standard Style thrown an errors:
'test' is not defined.
'expect' is not defined.
I can work around this issue by defining in my package.json file some global for jest.
"standard": {
"globals": [
"fetch",
"test",
"expect"
]
}
But definitely I do not think it is a good solution.
In my test case sum.test.js
const sum = require('./sum')
test('adds 1 + 2 to equal 3', () => {
expect(sum(1, 2)).toBe(3)
})
In my package.json :
"scripts": {
"test": "standard && jest",
}
Question:
I was able to find a solution.
In package.json
"standard": {
"env": [ "jest" ]
}
Or in the test case:
/* eslint-env mocha */
In your .eslintrc.js
file, include the following setting and you'll be good to go.
"env": {
"node": true,
"jest": true
}
If you are using a .eslintrc
or a .eslintrc.json
file, please use appropriate syntax.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With