Currently, I am using jest for testing my api calls. In addition, I utilize eslint to validate my test codes. However, since jest does not require explicit definition of methods such as test()
or expect()
, when running eslint, I encounter errors like:
4:1 error 'test' is not defined no-undef
8:3 error 'expect' is not defined no-undef
For instance, in my jest file index.test.js
, the code looks like:
test('API test', async () => {
const response = await axios.post('api call', {});
const { status, statusText, message } = response;
expect(status).toBe(400);
expect(statusText).toBe('Bad Request');
expect(message).toBe('No password.');
});
Since it's not necessary to define test()
and expect
for jest, I have been exploring eslint documentation to find a way to selectively ignore these rules in certain files while keeping the rest intact. Any suggestions or help would be greatly appreciated.
P.S. my .eslintrc
file looks like:
{
"parser": "babel-eslint",
"extends": "eslint:recommended",
"env": {
"commonjs": true,
"es6": true,
"node": true,
"browser": false
},
"parserOptions": {
"ecmaFeatures": {
"experimentalObjectRestSpread": true,
"jsx": false
},
"sourceType": "module"
},
"globals": {
"strapi": true
},
"rules": {
"indent": ["error", 2, { "SwitchCase": 1 }],
"linebreak-style": ["error", "unix"],
"no-console": 0,
"quotes": ["error", "single"],
"semi": ["error", "always"],
"multiline-ternary": ["error", "always"]
}
}