Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between setupFiles and setupTestFrameworkScriptFile

Tags:

jestjs

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?

like image 788
Hex Avatar asked Dec 01 '17 06:12

Hex


1 Answers

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)

like image 59
Tomasz Rozmus Avatar answered Sep 27 '22 16:09

Tomasz Rozmus