Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

How do i write a mocha test for this block of code?

Nyc is giving me a coverage that it isn't covered, given the test written for it. Am i missing something?

class Usercontroller {

// create an account
createAccount(req, res) {
if (!req.body.firstName) {
return res.status(400).send({
error: '400',
message: 'First name is required',
});
}

Here is the test written:

it('should return an error if no username is empty', (done) => {
chai.request(App)
.post('/api/v1/user')
.send({ message: 'User name is required' }) /
.end((err, res) => {
expect(res).to.have.status(400); 
expect(res.body).to.be.an('object'); 
expect(res.body).to.have.property('error'); 
done(err);
});
});

Comments