-
Notifications
You must be signed in to change notification settings - Fork 142
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
Using invocation verification with QUnit #304
Comments
I would recommend creating a test helper that wraps global.td = require('testdouble')
const originalVerify = td.verify
td.verify = function(...args) {
originalVerify.apply(this, args)
assert.ok(true)
} If you can get that to work, you should consider publishing a qunit plugin similar to |
thanks Justin! |
I added a QUnit assertion that internally calls In a "test setup" file, I added the following: import QUnit from 'qunit';
import td from 'testdouble';
QUnit.extend(QUnit.assert, {
verify() {
try {
td.verify(...arguments);
this.pushResult({
result: true,
message: 'Stub passed verification'
});
} catch ({ message }) {
this.pushResult({
result: false,
message
});
}
}
}); This allows me to use Another nice bit of this approach is that a failing verification doesn't blow up the rest of the test; it'll continue to make other assertions that might happen after the |
Might it make sense to extract this into a testdouble-qunit module? Similar to testdouble-chai or testdouble-jasmine? |
I was thinking the same. I can give that a shot in the next few days |
Hey @alexlafroscia, a few points of feedback you might be able to work into that package (github)
It'd be super fantastic if testdouble-qunit could accomplish both of these things |
Sure, I can split it out into a more generic package and an Ember addon. I modeled the approach after |
Just to follow up, it's now two separate repos:
There's a whole documentation site here: |
Fantastic! Thanks for aping the style of the other plugins! |
Threw it in the README 8ba9ba0 |
Sure thing! I did notice that I unintentionally swapped the argument order that the others use in some cases. Do you have a preference on consistency with other tools? I'm happy to change it if you'd rather. |
Hey Justin, thanks for the library! Love it!
I'm currently using testdouble with QUnit via Ember. QUnit expects each test to have at least one assertion, but it doesn't recognize
td.verify()
as an assertion. A few work around are:assert.expect(0)
at the top of the test. I don't like this becausetd.verify()
is an assertion and this is saying there are no assertions.assert.ok(true)
aftertd.verify()
.I considered doing something like
assert.ok(td.verify(...))
, buttd.verify()
returnsundefined
. This approach seems the most clear iftd.verify()
returned something truthy. Have you heard of anyone experiencing this issue and how they solved it? If not, what are your thoughts on havingtd.verify()
returntrue
when the assertion passes?The text was updated successfully, but these errors were encountered: