warnings with td 2.0.1
Closed this issue · 1 comments
everywhere i use .to.have.been.calledWith
now results in this warning:
Warning: testdouble.js - td.verify - test double `fetch` was both stubbed and verified with arguments ("https://foobar.com/blah", {
method: "POST",
headers: {Accept: "application/xml", "Content-Type": "application/json"},
timeout: 5000,
body: "{\"c\":3,\"d\":4}"
}), which is redundant and probably unnecessary. (see: https://github.com/testdouble/testdouble.js/blob/master/docs/B-frequently-asked-questions.md#why-shouldnt-i-call-both-tdwhen-and-tdverify-for-a-single-interaction-with-a-test-double )
Hi @modosc, I suspect that your tests are probably doing calledWith
expectations against testdouble objects that have been stubbed. testdouble-chai is just a thin wrapper around td.js's built-in verify
function, which is where this warning is coming from.
Here's a quick example:
describe("verifying stubbed objects", function() {
beforeEach(function() {
this.double = td.function();
td.when(this.double('hi')).thenReturn(42);
var foo = this.double('hi');
});
it("verifies a stubbed testdouble object (td.js-style)", function() {
td.verify(this.double('hi'));
});
it("verifies a stubbed testdouble object (chai-style)", function() {
expect(this.double).to.have.been.calledWith('hi');
});
});
One of these specs uses td-chai's calledWith
expectation while the other uses testdouble's own verify
, but they both result in this warning:
Warning: testdouble.js - td.verify - test double was both stubbed and verified with arguments ("hi"), which is redundant and probably unnecessary. (see: https://github.com/testdouble/testdouble.js/blob/master/docs/B-frequently-asked-questions.md#why-shouldnt-i-call-both-tdwhen-and-tdverify-for-a-single-interaction-with-a-test-double )
The testdouble docs have a great page on why they discourage this.
If you prefer to suppress these warnings, you can put td.config({ ignoreWarnings: true })
somewhere in your test suite setup (as per these testdouble config options), but note that this will silence all warnings, not just the ones about verifying stubs.