-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
🚀 Feature: Scoped globals #2656
Comments
I'm not a fan of encouraging use of globals. It would be better if we could teach people how to avoid this pattern. That's the whole reason for the global leak detection in the first place |
This kind of thing would be really nice for testing simple browser things with injected DOM mocks in Node. Basically, I just want Problem is, that's plainly not possible without some really ugly DI that would otherwise be unnecessary (it generally targets a browser environment, so injecting Edit: I worked around this issue by just wrapping |
I've actually been able to successfully use This works very similar to how context(... {
thix.ctx.currentUser = () => factory.create('user');
it("returns the right user id", function() {
// doesn't matter if this mutates currentUser
expect(response.id).to.equal(this.currentText.ctx.currentUser());
});
}); That is a little cumbersome unfortunately, so THIS is where I think a new feature would be useful. Just some syntactic sugar to allow the easy setting and getting of custom variables (or maybe require them to be functions?) on the ctx object (or a sub-object or separate object that is also "cloned" in the same way). Ideally, it would actually be more than syntactic sugar, and would convert a function into a singleton that is run once, and the result stored and returned upon additional runs within the same test. |
This has been |
Sometimes I write tests that modify a global in a
beforeEach
and cleanup restore the global in anafterEach
. Right now this is a violation of the global variable leak detection. To get around this I allow modifications to explicit globals. However, it would be more ideal to allow global 'leaks' within the context of a suite. Something like this:The text was updated successfully, but these errors were encountered: