I'm using Chai + mocha + karma for testing my js...
I've got a simple function that will take a number and add 2:
function name(str) {
return str + ' has come online';
}
I receive a assertion error, AssertionError: expected [Function: add] to be a string but I'm not sure why since it is a string...
describe("Number", function() {
it("Should return a string value", function() {
expect(name).to.be.a('string');
})
});
The test is throwing an error because it is checking the function name itself, not the result of invoking the function. You would need to do:
expect(name('something')).to.be.a('string');
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