I am trying to test my code using expect in nodejs. I required expect in code and I wanted to use a feature of expect called toBeA(). But unfortunately I am receiving error and unable to solve it. So,I am posting it here.
const utils = require('./utils');
const expect = require('expect');
it('should add two numbers', () => {
var result = utils.add(33,17);
expect(result).toBe(50).toBeA('number');
});
module.exports.add = (a,b) => {
return a+b;
};
When I run the code I receive this error
TypeError: Cannot read property 'toBeA' of undefined
You cannot chain tests. toBe doesn't return anything, hence the error. You want
expect(result).toBe(50);
expect(result).toBeA('number');
(although the first one implies the other so you might as well omit it)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With