basecase / testdouble-chai Goto Github PK
View Code? Open in Web Editor NEWChai assertions for testdouble.js
License: MIT License
Chai assertions for testdouble.js
License: MIT License
Tests are failing now in new versions of Node because of how errors get toString
ed, I think. Or something. Whatever, anyway, the fix is to just turn them into regex matches instead of ===
.
Thanks for creating such a handy little library!
The output of calledWith
with seems to be a bit broken when using the contains
matcher. Here's what I get when using testdouble.verify
:
testdouble.verify(requestMock(testdouble.matchers.contains({
headers: { "Authorization": "Bearer ACCESS_TOKEN" },
method: "GET"
})));
Wanted:
- called with `(contains({headers: {Authorization: "Bearer ACCESS_TOKEN"}, method: "GET"}))`.
But was actually called:
- called with `({
method: "POST",
url: "http://graph:8989/api/query",
headers: {Authorization: "Bearer ACCESS_TOKEN"},
json: {"@class": ".Query"}
})`.
And this is the output when running with testdouble-chai:
expect(requestMock).to.have.been.calledWith(testdouble.matchers.contains({
headers: { "Authorization": "Bearer ACCESS_TOKEN" },
method: "GET"
}));
[
{
- "headers": {
- "Authorization": "Bearer ACCESS_TOKEN"
- }
- "json": {
- "@class": ".Query"
- }
- "method": "POST"
- "url": "http://graph:8989/api/query"
+ "__matches": [Function]
+ "__name": "contains({headers: {Authorization: \"Bearer ACCESS_TOKEN\"}, method: \"GET\"})"
}
]
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 )
Man, all the coolest projects have like a million sweet badges at the top of their README. I should have those too so I can be cool.
I know that testdouble-chai
requires testdouble
, but there are instances where you may not actually need it as a peer dependency. For example, I'm using testdouble-chai
in Ember through ember-cli-testdouble
and ember-cli-testdouble-chai
. Because the wrapper packages provide the libraries, NPM does not consider them peer dependencies, even though I have both. Is is possible to remove the explicit peer dependency? I can't shrinkwrap my package because of this issue.
testdouble
creates quite useful message when a verification is failed.
testdouble-chai
generates more concise message which is lacking helpful data sometimes.
For example,
testdouble.verify( stub(), {times: 0, ignoreExtraArgs: true} );
generates the following message:
Error: Unsatisfied verification on test double `bound `.
Wanted:
- called with `()` 0 times, ignoring any additional arguments.
But was actually called:
- called with `("[test]", "debug")`.
Whereas the corresponding assertion
expect( stub ).not.to.have.been.called;
prints the following error:
AssertionError: expected [test double for "bound "] not to have been called, but it was.
Is it possible to have more detailed error messages containing data about call arguments?
Sometimes it can be very useful to find and fix tests.
Need to update to work with v3
I was wondering why my tests were not passing, and it looks like there is a bug in your plugin. See the sample test below:
beforeEach(function() {
this.subject = td.function("dubs");
this.wrapper = td.function("wrapper");
td.when(this.wrapper()).thenCallback(true);
});
describe(".called", function() {
it("passes if the callback testdouble was called", function() {
this.wrapper(this.subject);
expect(this.subject).to.have.been.called(); // this fails
expect(this.subject).to.have.been.calledWith(true); // but this passes
});
});
(Moreover with test double 1.6.0, npm run test
reports another test failing but I don't know if it's related)
The unit tests pass right now because we're only using one version of testdouble.js
. When you actually npm install testdouble-chai
and use it in a project, the fact that it installs its own copy of testdouble.js
means there is more than one callsStore
object out there and they can't read one another's recorded calls.
Hi I would like to have calledCount
method available. I did try to make PR but got lost in all those arguments. It would have been working like this
it("can tell you if a testdouble object was called an exact amount of times", function() {
var td = testdouble.function();
td("hi");
expect(td).to.have.been.calledCount(1);
});
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.