TypeError: Expect is not a function
11,230
Solution 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
Solution 2
You are assigning the result of calling the function chai.expect to your variable chai, which do not make sense.
Instead, you need to assign a reference to this function, like this:
var expect = chai.expect;
(without the parentheses)
Related videos on Youtube
Author by
user3142695
People who say nothing is impossible should try gargling with their mouths closed.
Updated on May 25, 2022Comments
-
user3142695 almost 2 years
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) }) }) })