Seeking integration tests using Jest for an API endpoint. Here's the specific endpoint:
http://localhost/universities/ucla/class/2013/studentalis/johndoe
. When tested with a put request, it returns 201 on Postman.
However, the testing encountered a timeout issue due to an error in the updateStudent.js file. The problem lies in parsing the URL parameters:
function getQuery(req, studentid, id) {
return {
universityName: req.params.universityName.toString(),
class: req.params.class.toString(),
studentAlias: req.params.studentAlias.toString()
};
}
The error message received is "TypeError: Cannot read properties of undefined (reading 'toString')". Upon investigation, it was found that req
is indeed an object, but req.params
is empty leading to undefined
values in
req.params.universityName.toString()
. This indicates a probable incorrect way of setting the URL params. Any suggestions on the correct syntax?