I read the document and got confused on the difference between these two. I know codes in setupFiles would be executed before codes in setupTestFrameworkScriptFile. What else differences do they have?
I guess codes in these two would be executed before each test. Does that mean if I have 10 it(); they are executed 10 times?
setupTestFrameworkScriptFile
and setupFiles
are executed before each file containing tests. If you have 10 tests in one file - no mater how many describe
's - it will run once. If in 2 separate files - it will run twice.
In both setupTestFrameworkScriptFile
and setupFiles
you can initiate globals, like this:
global.MY_GLOBAL = 42
setupFiles
run before test framework is installed in the environment.
In setupTestFrameworkScriptFile
you have also access to installed test environment, methods like describe
, expect
and other globals. You can for example add your custom matchers there:
expect.extend({
toHaveLength(received, argument) {
// ...
}
})
... or set a new maximum timeout interval:
jest.setTimeout(12000)
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