Support for `beforeEach` and `afterEach`
See original GitHub issueComing from node-tap
which is way to slow for my taste I wonder if zora has support for beforeEach
and afterEach
patterns?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:14 (5 by maintainers)
Top Results From Across the Web
Cypress basics: before(), beforeEach(), after() and afterEach()
I like to think of all hooks as being "squashed" together before executing a test or a describe() block. Using beforeEach block in...
Read more >Setup and Teardown - Jest
Jest provides beforeAll and afterAll hooks to handle this situation. ... It may help to illustrate the order of execution of all hooks....
Read more >Effective Use of beforeEach and afterEach in Angular Unit Tests
There are several reasons why using the beforeEach and afterEach methods can be beneficial when writing unit tests in Angular. First, using ...
Read more >beforeEach and afterEach inside support/index.js not being ...
I have some initialization scripts that run a bash script with cy.exec inside beforeEach and afterEach in support/index.js file that should ...
Read more >34. Implementation of beforeEach and afterEach methods in ...
In this video we will see how to implement beforeEach and afterEach lifecycle methods in the Test suite - Jasmine Testing Unit Testing...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It is tempting but I consider such hooks anti patterns when in comes to testing, especially for unit testing(so do I for snapshots but it is another story).
Such “features” will probably not make it in zora’s core but sometimes people make me change my mind 😃
However zora is quite simple to extend, you can for example create a decorator:
to be used as
A compromise would be to ship such helper functions with zora or within another package
To be honest I don’t know, I have not dug too much. The hooks I mentioned in this thread are just examples to consider as so, and are not part of zora.
I personally find the usage of such constructs a bad practice (that is why they are not part of the core library) and would rather consider each test independently.
Which are more explicit and easier to maintain in the long term. I would eventually factorize with a spec decorator to follow DRY principles (like any code) but certainly not use things like
beforeEach
which create global context and tend to introduce coupling between the tests.That being said. You are correct: by default zora run all the spec function concurrently. However you can explicitly maintain a shared state or a sequence between sub tests with the
async/await
control flow like would to for any other JS code: