-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Context in before/afterEach calls #3553
Comments
It's not a bug, it's a feature. let hello;
beforeEach(function () {
hello = 'hi';
});
afterEach(function () {
console.log(hello);
});
describe('context', () => {
it('should work', function () {
console.log(hello);
});
}); |
This was quite the breaking change for us. I wish it had been mentioned in the release notes :-(. |
Apologies, we rewrote Jasmine and this happened as a result of that :( |
Closes skovhus#57 Context: jestjs/jest#3553
Closes skovhus#57 Context: jestjs/jest#3553
Closes skovhus#57 Context: jestjs/jest#3553
Closes skovhus#57 Context: jestjs/jest#3553
Closes skovhus#57 Context: jestjs/jest#3553
Closes skovhus#57 Context: jestjs/jest#3553
Closes skovhus#57 Context: jestjs/jest#3553
Closes skovhus#57 Context: jestjs/jest#3553
Closes skovhus#57 Context: jestjs/jest#3553
|
Just wondering, is there any article with explanation why |
It would be great to get an explanation for the removal of |
As Jest possibly moves towards TypeScript it might be worth revisiting
It's not necessarily a big deal especially if initializing the variable is trivial but if it's complex it can get slightly irritating. |
How about
This way you have strict null checks for the whole project, but you can mitigate it for test cases on your own risk. |
That seems pretty good. I didn't realize you could use the bang operator on declarations. You learn something new every day. Thanks! |
Yo, this needs to be fixed. How is it a "feature"? It's not necessarily a bug, but nobody gets any value out of the scoping not working as expected. It feels like bad design in user experience from the point of view of a user. |
Sorry for waking up a zombie thread, but is this behavior documented anywhere? I just ran into the same issue of writing completely "normal" JavaScript that broke in ways that seemed to defy all reasonable explanation until I found this issue. I'm happy to do it the jest way, but I don't really feel confident that I understand what that is? |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Do you want to request a feature or report a bug?
Bug. Related issues (Jasmine-related): #3506 #3505
What is the current behavior?
The
this
context is not shared over a single test: Before, during, and after.If the current behavior is a bug, please provide the steps to reproduce and either a repl.it demo through https://repl.it/languages/jest or a minimal repository on GitHub that we can
yarn install
andyarn test
.What is the expected behavior?
I should see
"hi"
printed twice. Instead, I seeundefined
printed twice.Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.
Jest 20.0.1.
Works on 19.0.0.
As an aside, I think it's best to recommend against
this
usage, especially as the style for JavaScript has moved toward() => {}
functions rather thanfunction() {}
functions. Just dealing with some old code here :) I felt this issue might be helpful in documenting Jasmine's behavior and discussing next steps for Jest.The text was updated successfully, but these errors were encountered: