Could you help me with the 4th scenario of these tests, even though I have tried to add the error it does not want to give me a positive response, I would appreciate it if anyone has an answer to solve this problem. I share the test and also the condition that I use to validate the required fields.
test('Create an issue with missing required fields', async function () {
try {
const res = await chai.request(server)
.post('/api/issues/test')
.send({
assigned_to: 'fCC'
});
//assert.equal(res.status, 400);
assert.isObject(res.body);
assert.property(res.body, 'error');
assert.equal(res.body.error, 'required field(s) missing');
} catch (err) {
throw new Error(err.response?.text || err.message);
}
});
Scenery:
4. If you send a POST request to /api/issues/{projectname} without the required fields, returned will be the error { error: 'required field(s) missing' }
I have already done everything you mentioned, but as I see it, the scenario is not happening because the response is coming as a string including the word “error”. I don’t understand why I am using res.json() in the response
This is what the freecodecamp test returns
[Error: {“error”:“required field(s) missing”}]
There is some ambiguity here the way you mention strings and objects, as objects can be stringified, and they can also contain strings.
Also, when you said
“I don’t understand why I am using res.json() in the response”
Did you mean to say that you don’t understand why you chose to use res.json() ? Or did you have to do so to follow some guidelines? It really helps to include as much information as you can, like links to your code, when asking for help.
Is this [Error: {“error”:“required field(s) missing”}] coming back as a stringified JSON object or is it an actual object? Have you tried console.log( typeof res.body.error) ?
Is there any way I can take a look at the api response myself?
Thanks for your interest, this is the repo where I uploaded the code that I am sending for testing, if anyone has a solution it would help me, I am stuck there.
Hello,
I apologize, I was not able to respond or see the forum.
I already tried the solutions but none of them worked, I am still reviewing them. Thank you for both of your time…