-
Notifications
You must be signed in to change notification settings - Fork 781
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
Add module-contextual 'test' function #978
Comments
Adding |
(@leobalter wrote at #979 (comment)):
Hm.. enforcing this lexically would be nice indeed. However I think adding it as-is would be fine first step as well. Given that the closures are executed immediately, there is very little room for that to not work as expected. And it's certainly no worse than today. We took a similar "fake it until you make it" approach for the Assertion API. We could add this in QUnit 2.x as an easy thing to optionally adopt and consider a more strict/lexically sound version for QUnit 3.0. |
OK. Let's explore some of the options we've gathered here.
👎 Status quoQUnit.module('Thing', hooks => {
hooks.beforeEach(() => {
// …
});
QUnit.test('foo', assert => {
assert.true(Thing.foo(1));
assert.true(Thing.foo(2));
});
QUnit.test('bar', assert => {
assert.false(Thing.bar(4));
assert.false(Thing.bar(7));
});
QUnit.module('SubThing', hooks => {
QUnit.test('quux', assert => {
assert.true(SubThing.quux(-1));
assert.false(SubThing.quux(-2));
});
});
}); 👀 Option 1: Simply add to the
|
Would love to hear your thoughts, concerns, proposals, or just one or more emoji votes to show your support! /cc @qunitjs/community |
I have to admit that I'm not sure I understand what the benefit of this API change would be. To me these proposals look more verbose and complicated than the status quo (at least if you do something like |
What's to become of the Maybe I'm having trouble distinguishing what is the ideal end state (and maybe not attainable given history) versus some intermediate proposals to wean off of the current usage. |
For pure brevity, those static and global shortcuts indeed suffice. The intended benefit is to have known lexical bonds between a test and the module to which it belongs. This is not possible through global functions, I believe. Essentially it means that if code arrives later or is delayed by an await statement, the test or module might end up under an unrelated later module – whichever is the "current" one at that time that it executes.
@Turbo87 Agreed. This would involve no breaking changes. It is entirely optional. For adopting the slightly different syntax, one would automatically benefit the added layer of confidence and strictness, but I don't think it warrants a breaking change or other mandatory/encouraged change to existing tests.
It would remain, as does
From a high level, I'd like to see an end-state where:
From a technical level, with the currently presented ideas, it could work as follows:
|
What about |
@raycohen I see what you mean with Regarding The |
(this is a restatement of #670 (comment) , which itself referenced a discussion from #670 (comment) )
7be1d6c introduced the
QUnit.module( name, callback )
signature, which immediately invokes a callback to allow for definition of nested modules. However, doing so requires using globalQUnit.module
and/orQUnit.test
functions: https://jsfiddle.net/k9af94x7/This is ugly, and bad for the same reasons as use of global assertions like
QUnit.equal
instead of contextual assertions likeassert.equal
. We're fixing the assertions issue, and should do the same withmodule
andtest
by making them accessible from either context or arguments of the module callback, while fulfilling some goals to the maximum possible extent:module
andtest
callbacks, for future iterative convergenceassert
that do not pertain to assertions, since we might want to allow integrating external assertion libraries)My ideal vision would fully integrate the two functions, allowing code like:
However, if the above is a bit much, then I suppose we can just add
module
andtest
properties to the argument passed to module callbacks:Note that
module
is already incompatible withtest
, because arguments passed to their respective callbacks differ (respectively,moduleFns
—a.k.a.hooks
—vs.assert
).The text was updated successfully, but these errors were encountered: