Git Product home page Git Product logo

testdouble-chai's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

testdouble-chai's Issues

Assertions in tests should be fuzzier

Tests are failing now in new versions of Node because of how errors get toStringed, I think. Or something. Whatever, anyway, the fix is to just turn them into regex matches instead of ===.

calledWith format

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\"})"
         }
       ]

warnings with td 2.0.1

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 )

Remove required `peerDependency` on test double

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.

Show detailed message from testdouble

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.

called() always fails with td.when().thenCallback()

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)

Does not actually work when installed as a dependency

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.

CalledCount

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);
});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.