I'm trying to test an API endpoint in Node.js/Express using Chai HTTP.
Here is my code:
it('should UPDATE a single address on /address/<id> PUT', function(done) {
chai.request(server)
.put('/api/address/1')
.send({email: 'blob2@blob.com', fullname: 'Jim'})
.end(function(err, res) {
res.should.have.status(200);
res.should.be.json;
res.body.should.be.a('object');
res.body.should.have.property('email');
res.body.should.have.property('fullname');
res.body.should.have.property('id');
res.body.email.should.equal('blob2@blob.com');
res.body.fullname.should.equal('Jim');
done();
});
});
There is an entry in the database with id '1', but it doesn't get updated by this code, giving me an Assertion:
Uncaught AssertionError: expected 'john@john.com' to equal 'blob2@blob.com'
+ expected - actual
Doing the same test manually in Postman yields the expected result - update happens and an updated entry is returned. What am I doing wrong with Chai? My suspicion is that I have to .set something, but can't find anything in the docs. It's a x-www-form-urlencoded JSON that I'm trying to send.
Aucun commentaire:
Enregistrer un commentaire