Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: Expect is not a function

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)
    })
  })
})
like image 219
user3142695 Avatar asked Sep 04 '25 01:09

user3142695


1 Answers

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

like image 75
James Monger Avatar answered Sep 07 '25 13:09

James Monger