I am executing jest test. I don't want to specify jasmine.DefaultTimeoutInterval in all my test..
Is there any way where I can just specify once instead of giving in all my tests?
Yup, you can use: http://facebook.github.io/jest/docs/en/configuration.html#setuptestframeworkscriptfile-string
Thanks for the response. I tried created a setup file.js
And just mentioned :
var jasmine = require ('jasmine');
jasmine.DefaultTimeoutInterval = 20000;
And then I tried to call this file I'm setuptestframework
But somehow it stilll gave me a error for Async callback
Let me know if I am missing something here..
Don't require jasmine, use jest.setTimeout(x) or jasmine.DEFAULT_TIMEOUT_INTERVAL = x.
See how we do it here: https://github.com/facebook/jest/blob/master/test_setup_file.js
(Please use jest.setTimeout(x), jasmine global should really not be used)
Future references, testSetupFile.js:
// jest.config.js
module.exports = {
setupTestFrameworkScriptFile: './jest.setup.js'
}
// jest.setup.js
jest.setTimeout(10000)
Doesn't work, url is dead
I'm doing what @frangeris suggested and I'm not seeing my tests timeout increased- they're still timing out like they were before. Am I missing something? Is that still the best way to globally update timeouts?
I can confirm this does not work (anymore?), with Jest v24.7.1.
I'm using this configuration:
// jest.config.js
module.exports = {
setupFiles: [
'<rootDir>/test/setup.js'
]
};
// test/setup.js
console.log('set timeout');
jest.setTimeout(...);
Note that set timeout is properly logged before every tests. So... maybe jest.setTimeout() does not work? :thinking:
Thanks!
Hum, after some investigations I found this while looking at the definition of jest.setTimeout():
console.log(this._environment.global.jasmine) display undefined, so this._environment.global.jasmine._DEFAULT_TIMEOUT_INTERVAL is never calledthis._environment.global[testTimeoutSymbol] = timeout but I don't see where it is used in Jest packages@Kocal -
If you use setupFilesAfterEnv instead of setupFiles to call your jest.setTimeout() code, it should work. I've confirmed in my suite that calling jest.setTimeout() in setupFiles does not work, but setupFilesAfterEnv works (at least for my use case which is using jest 24.9.0).
Oh, okay. I was planning to use #8456 but I will give setupFilesAfterEnv a try.
Thanks :)
setupFilesAfterEnv is working properly, thanks @skratchdot :)
Most helpful comment
Future references, testSetupFile.js: