GithubHelp home page GithubHelp logo

chai-nock's People

Contributors

bvjones avatar chrisandrews7 avatar dependabot[bot] avatar gledrich avatar rkclark avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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

chai-nock's Issues

Using chai-nock with asynchronous functions?

Hi,

I've been trying to get chai-nock to work with asynchronous code but have failed so far unfortunately.

Let's say I have a function that make a PUT request: async function makePost() and I try to verify the payload. When I try to test it with mocha like this:

describe("example", () => {
  it("should work", () => {
  const scope = nock(Url)
      .put(/.*/)
      .reply(200, "foo");

  makePost().should.be.fulfilled.and.eventually.deep.equal("foo");
  scope.should.have.been.requestedWith("my expected payload here");
});
});

Then this never works: I get errors from chai-nock that the request didn't match:

AssertionError: expected Nock to have been requested with exact body 'my expected payload here', but was requested with body undefined

To me that looks like the request is checked before the asynchronous function actually resolves. Unfortunately, I have not been able to properly defer the check. I have tried to use chai-as-promised, declaring the test function in it() as async and awaiting the result of makePost and probably various other things, but they all result in the same outcome (only sometimes it is masked by the fact that the assertion fails in a non-resolved promise that is only sometimes reported as a warning by node).

Is there a way how I could make this work? I really need to support async functions unfortunately.

Nock beta releases

Hi! We've started making beta releases toward the next major release of nock. Would you be up for giving one of them a shot in some tests for this library to help us ensure compatibility?

npm
npm@beta

Note that v11, when it's released, will drop support for Node 6.

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.