My testing with Jest takeaways
- Test files (i.e suites) are run in parallel unless you use the
- Tests within a file are always run sequentially (in series).
- A tests file is first parsed to collect tests, this is the collection phase.
- Tests are run in the order they were collected.
describeis a good mean to organise the code BUT also influences the scope of the setup/teardown functions like
- In a
afterAll()are executed respectively before and after ALL of the tests collected from this
describeblock and all its nested
- In a
afterEach()are executed respectively before and after EACH of the tests collected from this describe block and all its nested
- BEWARE, any code line inside of
describethat is not part of a setup/teardown function nor a test (aka
it) block, is executed during the collection phase, so avoid instructions for cleaning in there as they will be executed before the first test is run, what may not be of your intent
- There is ONE instance of a global variable per Test file (e.g one JSDOM instance), shared across all the tests within the tests file.
- Same goes with a mocked module, so make sure that you call your reset
functions such as
mockReset()either in a setup/teardown function or at top/end of each tests if you prefer that style