-
Notifications
You must be signed in to change notification settings - Fork 30
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
fix(test-helper): Fix Sinon/QUnit Assertion Issue #529
base: master
Are you sure you want to change the base?
Conversation
This change wraps the pass/fail from sinon.assert in a Qunit.ok assertion. This makes it so that Qunit detects sinon.assert as an actual assertion. sinon.assert methods are not detected as QUnit Assertions. When no qunit assertions exist in the test, Qunit will throw an error: "Expected at least one assertion, but none were run - call expect(0) to accept zero assertions." This is expected behavior from Qunit, but when we assert with sinon.assert, there is technically assertion there.
4dba412
to
6e406c0
Compare
@@ -11,4 +12,7 @@ import { createSandbox, restoreSandbox } from './sinon-sandbox'; | |||
export default function setupSinon(testEnvironment = self.QUnit) { | |||
testEnvironment.testStart(createSandbox); | |||
testEnvironment.testDone(restoreSandbox); | |||
|
|||
sinon.assert.pass = (assertion) => self.QUnit.assert.ok(true, assertion); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it ok that we are importing sinon
here? Should this be something passed in? Should it be self.sinon
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's fine to import sinon here, because it's a required dependency through ember-sinon. Even beyond that, though, we shouldn't have to expect people to use this package if they're not using sinon. That's not a workflow we need to support, so import is fine here!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we import QUnit here or is it required to be grabbed from self
for some reason?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just grabbed it from self
because you did on line 12. Which also means we could probably swap it to testEnvironment
instead. I'm without opinion, which would you prefer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, great point. I think we should definitely swap it to testEnvironment to make sure that still works, and then maybe separate from this change we should consider whether we can just do
import * as QUnit from 'qunit';
I don't trust my past self to have made that decision wisely, but maybe there was a reason for it? XD
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opened an issue to separate that question from this PR: #530
Are you sure this works? This open issue on the QUnit project seems to indicate that hooking up sinon.assert and QUnit.assert isn't this easy: qunitjs/qunit#1749 |
I can confirm that this fixed the QUnit assertion error outlined in the description by adding it to my local packages
I think it depends on what you're wanting from the integration. The goal here for me is to not have QUnit yell at us for no assertions when we're using Thoughts? |
I'm mostly concerned about the impact of the caveat in that ticket, though I'm not sure I fully understand the implications:
|
That's reasonable. Let me do a little digging to better understand that and I'll comment back on this PR with what I can find. :) |
Thanks! The TLDR here is that I fully support what you're trying to do, and I just want to make sure that we're doing it in a way that fully supports how people use Sinon and QUnit today. |
Here's what I found out:Sinon "Sandboxes" remove the need "to keep track of every fake thing created, which greatly simplifies cleanup". I've never looked at this code before, so take this with a grain of salt and a dash of skepticism, please. https://github.com/sinonjs/sinon/blob/master/lib/sinon/sandbox.js Sandboxes create a local Krinkle initially linked to v.2.0.1 docs for Sinon, but according to the v11.1.2 docs, that Lastly, I'm a little unsure about this particular bit of Krinkle's comment:
Not necessarily that it wouldn't be easy, but more about their definition of a "local assertion object". Thoughts on what they're referencing directly? Maybe I'm not totally sure where to dig from here, but I think this answers the initial question. Let me know if you want me to dig into something else. I'm learning a ton about |
Yea, |
This change wraps the pass/fail from
sinon.assert
in aQunit.ok
assertion. This makes it so that Qunit detectssinon.assert
as an actual assertion.sinon.assert
methods are not detected as QUnit Assertions. When no qunit assertions exist in the test, Qunit will throw an error:This is expected behavior from Qunit, but when we assert with
sinon.assert
, there is technically assertion there.