-
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
Core: Skip tests with no/falsy callbacks #714
Conversation
765771c++ I don't like this kind of feature. Not passing a function parameter to the test seems too loose. Depending on the kind of project, QUnit can be extended with @JamesMGreene's qunit-pending. I repeat @Krinkle's arguments in #434 (comment)
|
Neither of those describe my use case, which is skipping tests at runtime for lack of client/library functionality:
|
how about This might also be abstracted in a function. |
Indeed. It's precisely because that expression is so damn ugly that I'm proposing this change, and will probably define |
@gibson042, would you make another PR for 765771c? That commit can be merged faster, I just want to assure we get a separate review for that, and maybe more eyes. |
Looks to me like you want to make the exceptions more explicit. If you're okay with using For example (untested): function testInIE9(name, callback) {
QUnit[ document.documentMode === 9 ? "test" : "skip" ]( name, callback );
} |
We'll have enough separate conditions to make a single method more valuable. It may not be |
Let's revisit this after #715 landed, makes it easier to see the changes in the tests. |
Landed #715, @gibson042, would you rebase it? probably removing 765771c might solve it. |
Logging tests
Gratuitous demonstration
c018044
to
ae84fc3
Compare
Done. |
<3 <3 <3 Well, I'm feeling sad by still disagreeing with these proposed changes. Maybe the other contributors might accept it, and I can say the changes are way easier to review now. |
I agree with @leobalter on this. @JamesMGreene @Krinkle do you want to take a look as well? |
I agree with some of the previous comments. We should very much avoid patterns like QUnit[ bool ? "test" : "skip" ]( name, function () {
} );
QUnit.test( name, function () {
..
..
..
}, bool );
QUnit.test( name, bool && function () {
}); Given the current API ( QUnit.test( name, function () {
} );
QUnit.skip( name );
QUnit.skip( name, function () {
} );
if ( !bool ) {
QUnit.skip( name );
} else {
QUnit.test( name, function () {
} );
} The downside is that it repeats the test name twice and makes for a test suite where the top of your scope is no longer a clean uninterrupted flow of test definitions. Note I generally discourage this kind of conditional skipping in test suites as, more often than not, it's indicative of a problem with the source code or its API. It should rarely be necessary to do that in the first place. However, while it's slightly different than the API signature you propose, I'd implement "conditional skip" as additional argument in between the name and callback parameters: QUnit.test( "name", bool, function ( ) {
..
} ); It avoids any dangling boolean expressions after the function, and avoids inline trickery with the callback parameter. The only thing I don't like about it is that it isn't clear what the boolean value is supposed to do. It should be straight forward to implement, though. It changes the meaning of an existing parameter but does so in an unambiguous and backwards-compatible way. Alternatively, I can also imagine having something like this: QUnit.skipIf( bool, "name", function () {
..
} ); Thoughts? |
QUnit.testIf( supported, "name", fn ); |
So...? QUnit.testIf = function( condition, name, callback ) {
if ( condition ) {
QUnit.test( name, callback );
} else {
QUnit.skip( name );
}
}; Could just put that in a helper in Core somewhere, to see if that works. |
I guess the question is whether or not |
Well, I'm okay with that. We can also revisit this in the future, after all that's how we came up with skip. |
Did we come to a conclusion on this? I am looking for a feature such as JUnit's assumeTrue where the test will not run if a condition is false |
@binodpanta I don't know if this is something we want to reconsider for QUnit core, but this is something you can already do. You can just augment the QUnit object with a new method, as @jzaefferer demonstrated above. |
I'm opening this as a pull request instead of an issue to make rejecting it easier if that is the final determination. If it is accepted, it should be coupled with a documentation change at jquery/api.qunitjs.com, which I am more than happy to submit.
In #637 (comment) and #434 (comment), @JamesMGreene advocated for a syntax like
QUnit.test( "pending test" )
. 3f08a1a then addedQUnit.skip
, but not the above Mocha-like implicit skip. Although I was not a fan of that style at the time, thinking about how to isolate Sizzle dependencies in the jQuery core suite has me reconsidering. In particular, I'd like to take advantage of something very similar in order to inline test preconditions rather than wrap tests in if blocks:QUnit.test( "name", preconditionsMet() && fnTest )
.Implementation broke no existing unit tests, and in fact I found an opportunity to use the new functionality within the logs tests as I was updating them: ae84fc3.