I have created some of my mocha test cases to use supertest to use server APIs.
All the test cases are almost the same, ie. they use supertest to fire an API request, and check the response like so:
describe('GET /my/api/', () => {
before(done => {
request(myServer)
.post('/some/path/')
.send(testData)
.set('Accept', 'application/json')
.expect('Content-type', /json/)
.expect(200)
.end((err, res) => {
currentData = res.data;
done();
});
});
it('really works', done => {
request(myServer)
.get(`/some/path/`)
.set('x-access-token', currentData)
.set('Accept', 'application/json')
.expect('Content-type', /json/)
.expect(200)
.end((err, res) => {
expect(res.data).to.equal( ... );
done();
});
});
});
Things were running really smoothly, until recently when I mysteriously started getting this weird error for each and every before block and it block, like so:
GET /my/api/
1) "before all" hook
double callback!
Some basic searching lead me here, but I couldn't find any solution in there.
Any explanations?
Fixed it myself by clearing my database. However, I don't know the reason for this.