Tell us what’s happening:
So I’m working at the Personal Library project and I’m having an issue with one of the test. The test passes if I hard-code the book ID in the .get()
method, but it doesn’t if I send the ID within the .send()
method (commented lines in the sample code below). Loggin the response of the test return an empty object.
Also this part of the API works as expected if I visit it in the browser (I get a book object with _id, title, etc.).
Project so far on Replit (test at lines 111-128).
Any suggestion?
Your code so far
test('Test GET /api/books/[id] with valid id in db', function(done){
chai.request(server)
.keepOpen()
.get('/api/books/647de934b733d0ae5fca0e4f') // works...
// .get('/api/books/:id')
// .send({ // this should be the same
// id: "647de934b733d0ae5fca0e4f" // but doesn't work
// })
.end((err, res) => {
assert.equal(res.status, 200);
assert.equal(res.type, 'application/json');
assert.isObject(res.body, 'res.body should be an object');
assert.property(res.body, '_id', 'res.body should have an _id property');
assert.property(res.body, 'title');
assert.property(res.body, 'comments');
done();
});
});
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/113.0
Challenge: Quality Assurance Projects - Personal Library
Link to the challenge: