comparethemarket / chai-nock Goto Github PK
View Code? Open in Web Editor NEWChai Nock extends Chai with a language for asserting facts about Nock.
License: MIT License
Chai Nock extends Chai with a language for asserting facts about Nock.
License: MIT License
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.
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.