But why the empty req.body comes into travellers() in server.js?
P.S. Change PUT to POST didn’t help.
Even with incorrect data, something must go into req.body in travellers() ?
I found my error: I thought the ‘body-parser’ is deprecated in Express 4, so changed the server code incorrectly. With original server.js all tests passed.
Thanks.
test('send {surname: "da Verrazzano"}', function (done) {
chai.request(server)
.put("/travellers")
.send({ surname: "da Verrazzano" })
.end(function (err, res) {
console.log('>>>RES BODY =', res.body); // OK
assert.equal(res.status, 200, 'status must be 200');
assert.equal(res.type, 'application/json', 'reponse type must be json');
assert.equal(res.body.name, 'Giovanni', 'body.name must be "Giovanni"');
assert.equal(res.body.surname, 'da Verrazzano', 'body.surname must be "da Verrazzano"');
done();
});
}); // end test
On repl.it:
Listening on port 3000
Running Tests...
Functional Tests
>>>RES BODY = { name: 'Giovanni', surname: 'da Verrazzano', dates: '1485 - 1528' }
✓ send {surname: "da Verrazzano"} (89ms)
Integration tests with chai-http
✓ Test GET /hello with no name
✓ Test GET /hello with your name
✓ send {surname: "Colombo"}
4 passing (184ms)
But check res.body.name & res.body.surname fails on freecodecamp:
// running tests
You should test for 'res.body.name' to be 'Giovanni'
You should test for 'res.body.surname' to be 'da Verrazzano'
// tests completed
Please do not comment out the other code given in the boilerplate or past tests. The freeCodeCamp tests rely on the order and number of tests given in each suite, and you commenting them out causes the tests to think some do not exist, and are testing for the wrong sections.
No.
Without commenting future tests, the application won’t start due to assert.fail() calls in the tests that I haven’t done yet.
In my case the error is “ReferenceError: browser is not defined” (the next lesson).
That error only comes about, if you have changed something you should not have. I suggest you re-copy the boilerplate, and only work within the sections you are meant to.
Many Campers struggle, because of adding/removing {} curly brackets, and miss-aligning the tests within the suites. So, watch out for this.