Hi Jest,
I am having a little bit confused here regarding how to add jest.setTimeout(10000) globally in setupTestFrameworkScriptFile. But I do not have see any clear example explicitly such an the code in jest.config.js. And I cannot find any example in
For current condition, I have :
jest.config.json
{
"reporters": [
"default",
"./node_modules/jest-html-reporters"
],
"setupTestFrameworkScriptFile": "jest-expect-message"
}
in my package.json
"scripts": {
"test": "jest ./__tests__/ --config ./jest.config.json --detectOpenHandles --no-cache"
}
So, how can I add jest.setTimeout(10000) globally in setupTestFrameworkScriptFile and also contains jest-expect-message? Could you please give an explicitly example?
Thank you. I appreciate for your help :)
"setupTestFrameworkScriptFile": "<rootDir>/my-thing"
// my-thing
require('jest-expect-message');
jest.setTimeout(10000)
Note that in Jest 24 we've renamed setupTestFrameworkScriptFile to setupFilesAfterEnv which is an array, at which point you could have:
{
"setupFilesAfterEnv": ["jest-expect-message", "<rootDir>/my-thing"]
}
Ah I missed something, how can I add reporters in setupFilesAfterEnv? @SimenB
Thank you so much @SimenB
https://jestjs.io/docs/en/configuration#reporters-array-modulename-modulename-options
So I tried with my package.json
{
"name": "test-saja",
"version": "1.0.0",
"description": "This is for Automated Test API",
"main": "index.js",
"scripts": {
"test": "jest ./__tests__/ --detectOpenHandles"
},
"repository": {
"type": "git",
},
"keywords": [],
"author": "QA",
"license": "ISC",
"devDependencies": {
"eslint": "^5.8.0",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-plugin-import": "^2.14.0",
"jest": "^23.6.0",
"jest-html-reporters": "^1.0.8",
"jest-runner-concurrent": "^0.1.1"
},
"dependencies": {
"dotenv": "^6.1.0",
"jest-json-schema": "^2.0.1",
"moment": "^2.23.0",
"randomstring": "^1.1.5",
"supertest": "^3.3.0",
"jest-expect-message": "^1.0.2"
},
"jest-runner-concurrent": {
"maxConcurrentTests": 100
},
"setupTestFrameworkScriptFile": "./jest.setup.js",
"reporters": [
"default",
"./node_modules/jest-html-reporters"
]
}
and my jest.setup.js:
require('jest-expect-message');
jest.setTimeout(10000);
But I found this error when run the test:
Expect takes at most one argument.
60 | body[element] = null;
61 | const response = await epRegister.register(body);
> 62 | expect(response.status, `request ${JSON.stringify(body)}`).toBe(tc.registerNegatif.withNullValue.status);
Seems jest-expect-message does not loaded
Please kindly your suggestion @SimenB
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.
This works for me in package.json:
"scripts": {
"test": "jest --setupTestFrameworkScriptFile=dotenv/config"
},
Most helpful comment
"setupTestFrameworkScriptFile": "<rootDir>/my-thing"Note that in Jest 24 we've renamed
setupTestFrameworkScriptFiletosetupFilesAfterEnvwhich is an array, at which point you could have: