Why do I get a TypeError: expect is not a function
when running this test file?
I've installed mocha and chai locally and run the test via yarn run test
which runs simply "test": "mocha"
.
var chai = require('chai')
var expect = chai.expect()
describe('Array', function () {
describe('#indexOf()', function () {
it('should return -1 when the value is not present', function () {
expect([1, 2, 3].indexOf(4)).to.be.equal(-1)
})
})
})
When setting expect
, you need to do this:
var expect = chai.expect
You are evaluating the function with ()
, which is not correct according to the documentation
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