/** Repetition is the mother of learning. **/
// Try it again. This time without help !!
test('send {surname: "da Verrazzano"}', function(done) {
/** place the chai-http request code here... **/
chai.request(server)
.put('/travellers')
.send ({surname: 'Giovanni'})
.end(function(err, res){
/** place your tests inside the callback **/
assert.equal(res.status, 200, 'response status should be 200');
assert.equal(res.type, 'application/json', "Response should be json");
assert.equal(res.body.name, 'Giovanni', 'res.body.name should be "Giovanni"');
assert.equal(res.body.surname, 'da Verrazzano', 'res.body.surname should be "da Verrazzano"' );
done();
});
});
This answer fails all 5 tests. I pretty much copied the code from the last lesson (which passed).
I can get 4 of the tests to pass; somebody in another post said if you add an extra }) at the end then it helps the test pass. The first test is still failing though: All tests should pass and expected 'failed' to equal 'passed'.
I don’t really understand what the error is, because it seems right. The status is 200, it’s using json, it checks for Giovanni’s name, and checks da Verrazzano is the surname. What else should I do?
I tested your code and got the same results. It doesn’t make sense that the test for ‘res.body.name == Giovanni’ says it’s passing, because it’s actually failing with your code.
Ahh, thank you! I added the name on line 3 and surname on line 9. (I think that was a problem too, I sent “da Verrazzano” and “Giovanni” both as surname.)
/** Repetition is the mother of learning. **/
// Try it again. This time without help !!
test('send {name: "Giovanni", surname: "da Verrazzano"}', function(done) {
/** place the chai-http request code here... **/
chai.request(server)
.put('/travellers')
.send({
name: 'Giovanni',
surname: 'da Verrazzano'
})
.end(function(err, res) {
/** place your tests inside the callback **/
assert.equal(res.status, 200, 'response status should be 200');
assert.equal(res.type, 'application/json', "Response should be json");
assert.equal(res.body.name, 'Giovanni', 'res.body.name should be "Giovanni"');
assert.equal(res.body.surname, 'da Verrazzano', 'res.body.surname should be "da Verrazzano"');
done();
});
});
A related question:
The lesson “API Response using Chai-HTTP IV” is supposed to take code from the previous lesson, API Response using Chai-HTTP III, and duplicate it. I looked back at my solution for III and I’m wondering if it has the same error:
In the test('send {...}') and the chai.request(server).send({...}) sections, I only send the surname (Columbus) and not the name (Cristoforo).
But the two assert.equal(res.body...) are testing for name, and surname.
I think the FCC test passed my solution in error. It needs to .send() the name as well?
I’m sorry, I think I was wrong in my previous comment. I believe the reason it failed was because you used the wrong surname the first time.
You do not need to .send() both the name and surname; you only need to .send() the surname. I believe this is why you (correctly) passed the previous lesson.
Let me know if this makes sense, or if you have any other questions!