[jest-plugin-set] Set variables should be created before beforeEach is called
See original GitHub issueDescription
Nested set
calls must ALL come before beforeEach
in order to be set properly. Otherwise, it’ll use the values from outer set
calls which is incorrect
Screenshot
Test Plan
Issue Analytics
- State:
- Created 6 years ago
- Reactions:4
- Comments:5 (2 by maintainers)
Top Results From Across the Web
How to pass variable from beforeEach hook to tests in jest?
Just declare sandbox so it is available in the scope of beforeEach and test: let sandbox; beforeEach(async () => { sandbox ...
Read more >Setup and Teardown - Jest
You have a method initializeCityDatabase() that must be called before each of these tests, and a method clearCityDatabase() that must be ...
Read more >Using Jest beforeEach to write better unit tests in JavaScript ...
In this post, we will delve into using Jest beforeEach properly to make unit testing better with JavaScript, let's get going! Jest before...
Read more >How I Was Completely Wrong About Setting Up/Tearing Down ...
So to test my constructor here, I developed the following test suite: ... describe 's scope meant that the beforeEach callback would get...
Read more >DSL - Kahlan
it : contains the code to test. Keep its description short and clear. Setup and Teardown. As the name implies, the beforeEach function...
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 Free
Top 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
Hi @bxt, thanks for your comment. If I remember correctly, the issue comes from something like:
It will log:
when it should be:
and if I remember correctly, the test should fail on this and return 2 instead of 10. Let me know if you’re seeing the same behavior.
(I wrote the code without testing, please excuse if there are small errors)
I ran into this also today. Here’s another repro.
Fails with
ReferenceError: x is not defined
on the second line.Pulling variables from inner contexts to use in beforeEach is definitely a useful pattern which can eliminate a lot of duplicate code. Something I always do in rspec.