chai-http
chai-http copied to clipboard
Test reports that it both passes and fails during sequential async operations
I'm writing an integration test to make sure the rate limiter middleware on my app is working. This necessitated sequential Promise execution to keep track of how many requests have been sent, since that affects the desired behavior in each pass. So I'm using Bluebird's mapSeries() function for this, and getting some weird output.
Here's my test code:
it(`should allow only ${allowedRequestCount} requests within frequency window`, function(done) {
this.timeout(0);
Promise.mapSeries(_.range(1, allowedRequestCount + 10), iter => {
return chai
.request(baseUri)
.get(resourcePath)
.set({
'content-type': 'application/json; charset=utf-8',
'transfer-encoding': 'chunked',
})
.send()
.then(res => {
if (iter <= 100) {
expect(res.body).to.deep.equal(expectedResponse);
}
done();
})
.catch(err => {
if (iter > 100) {
expect(err).to.have.property('status', 429);
expect(err).to.have.property('message', 'Too Many Requests');
}
done();
});
});
});
Which causes Mocha to yield this: