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

[QUESTION] is it possible to fail a test in the QUnit.testDone callback? #817

Closed
williamsbdev opened this issue May 4, 2015 · 6 comments

Comments

@williamsbdev
Copy link

In the QUnit 2.0 series, the assert is no longer global (good thing!) and is passed into each test's callback. When I made this upgrade, my testDone callback is no longer failing tests like it had been (because I had been using the global assert). I had some code that would check to see that all requests were properly mocked and if there were too many or too few mocks, I would fail the test. I see my error messages but doing a QUnit.assert.ok(false, "error message") has no effect on the test. Can someone please advise how I would be able to fail the test that just run from inside the testDone callback?

Thanks!

@jzaefferer
Copy link
Member

That's an interesting usecase, though one that the logging callbacks like testDone were never intended for. For this kind of assertion, I recommend using the module's afterEach callback instead. You may still need a bit of duplication to apply that check for all modules, but that's currently the best option. Let us know if that works for you.

@williamsbdev
Copy link
Author

This will be in every module and so it is not desirable to put this into each afterEach. Would you like me to open a feature request issue?

@jzaefferer
Copy link
Member

Assuming you abstract the necessary logic, you'd add 3-4 LOC per module. Also assuming one module per file, a reader of that file could quickly figure out where that shared setup is defined, compared to having it in just one place somewhere else.

That said, we've had a discussion about that feature before, even implemented it at some point, but dropped it before release. I can't remember that name of the ticket right now, but can look for it later...

@williamsbdev
Copy link
Author

Correct me if I'm wrong but even in the afterEach, it is not possible to fail a test. So while I really don't want to add something to every module, I don't think it's even possible without wrapping the test function and doing my custom failure.

@gibson042
Copy link
Member

@jzaefferer
Copy link
Member

So the answer to the question in the subject, can a testDone callback fail a test, is no, it cannot. The suggested workaround is to use module level callback (beforeEach, afterEach).

The attempt to implement global beforeEach/afterEach callbacks can be found in #633, while #681 discusses why we ended up removing them again. As I wrote there:

it should be trivial to bring this back in whatever form we decide on later.

That's still a discussion we can have, though since this issue isn't about that, I'm going to close this for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants