Skip to content
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

Added a warning feature #189

Closed
wants to merge 2 commits into from
Closed

Added a warning feature #189

wants to merge 2 commits into from

Conversation

nathanmacinnes
Copy link

This allows a warning to be thrown by a test at any point using the warn function, but the test still counts as a pass. I've found this quite useful to notify myself/others that something needs attention, but hasn't yet had a test implemented for it. For example:

test("that the function will return the element passed by a selector", function () {
    var linkElement = document.getElementById('external-link');
    if (document.querySelectorAll) {
        var result = myHelper.query('#container a');
    } else {
        warn("Browser doesn't support querySelectorAll. Implement test for alternative interface if we're going to support this browser.");
    }
});

@masklinn
Copy link

Maybe some sort of more general "skipping" idea (which would print a warning with relevant info)? Something along the lines of:

test("that the function will return the element passed by a selector", 
    skipIf(!document.querySelectorAll, "Browser doesn't support querySelectorAll. Implement test for alternative interface if we're going to support this browser.", function () {
        var linkElement = document.getElementById('external-link');
        var result = myHelper.query('#container a');
}));

and a straight skip primitive would be provided for unconditional test skipping (to temporarily disable tests, but keep a trace that there are disabled test and a note as to why they've been disabled).

This would also allow for skip and skipIf "restarting" the suite if they're used in asyncTest, without the developer having to do so manually in that case.

@nathanmacinnes
Copy link
Author

Hmmm... I like that idea. I'll have a go at it when I get chance. I remember using skips in an nUnit framework (maybe it was jUnit?) and marking tests incomplete too... I'll abandon straightforward warnings in favour of those if I can implement them.

@masklinn
Copy link

Yeah it's not a new idea, I got them from Python's unittest2/Python 3's unittest which has pretty nifty skip decorators. I'm sure many other test frameworks have them.

(I considered the idea of putting skip outside test as in Python, but I don't see how that would work since the test would already have executed, short of wrapping test in an other function which would be pretty crummy)

@nathanmacinnes
Copy link
Author

Yes, I've thought of that. The obvious interface would be:

test("my test", function () {
    skip("Test not yet complete");
    equal(someFunction(), "foo");
});

But the problem is, what if someFunction doesn't yet exist. This will still throw an error, and the error will need to be "removed" and not written to the console. Could be quite tricky. Anyways, I'll close this pull request, revert my fork and try to implement this feature afresh.

@masklinn
Copy link

That could be handled with a throw (to return directly into Test#run) but I don't know if that fits in QUnit's current practices. And it would require a big wrapper all around Test#run with some sort of test+throw in the current "withtrycatch" branch.

There might be problems with asyncTest though, as it would skip the start.

@Mottie
Copy link

Mottie commented Dec 6, 2012

Check out this answer on stackoverflow on adding a testSkip() function:

QUnit.testSkip = function( testName, callback ) {
    QUnit.test(testName + ' (SKIPPED)', function() {
        if (typeof callback === "function") {
            callback();
        }
        var li = document.getElementById(QUnit.config.current.id);
        QUnit.done(function() {
            li.style.background = '#FFFF99';
        });
    });
};
testSkip = QUnit.testSkip;

@englercj englercj mentioned this pull request Mar 28, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants