Reputation: 1673
I am new with mocha, right now i am doing api call invocation with mocha, but i am getting this error Uncaught AssertionError: expected { Object (domain, _events, ...) } to have status code 200 but got 401
, can anyone please help me why i am getting this error ? here is my full code of it
it('Get Organizations', function(done) {
let current_token = currentResponse['token'];
let headers = [{"content-type":"application/json","vrc-access-token": current_token }];
console.log(headers);
chai.request(app)
.post('entities')
.set(headers)
.send({"key":"organizations","operation":"findAll"})
.end(function (err, res) {
currentResponse = res.body;
expect(err).to.be.null;
expect(res).to.have.status(200);
done();
});
});
Upvotes: 1
Views: 529
Reputation: 82096
Just based on the docs, it doesn't look like chai-http supports setting headers in this way, they need to be added separately i.e.
chai.request(app)
.post('entities')
.set('Content-Type', 'application/json')
.set('vrc-access-token', current_token)
.send({"key":"organizations","operation":"findAll"})
.end(function (err, res) {
currentResponse = res.body;
expect(err).to.be.null;
expect(res).to.have.status(200);
done();
});
Upvotes: 2