Reputation: 5402
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');
})
});
Upvotes: 2
Views: 11674
Reputation: 8388
If you are using assert
you can do it that way:
assert.typeOf(name('someting'),'boolean');
You can check the documentation for more details
Upvotes: 1
Reputation: 6706
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');
Upvotes: 12