How can I solve "ReferenceError: expect is not defined" error message?

Mocha is a test framework; you need to provide your own assertion lib as https://mochajs.org/#assertions states. Thus, expect is indeed undefined because you never defined it.

(I recommend chai)

npm install chai

then

(see Amit Choukroune's comment pointing out to actually require chai)

then

var expect = chai.expect;

Try

First, in the terminal

npm install expect.js

And in your code:

var expect = require('expect');

After you install Chai as other posts suggest, with the es6 syntax you should put the import at the top

import {expect} from 'chai';

let chai = require('chai');

var assert = chai.assert;

describe('Array', function() {
  describe('#indexOf()', function() {
    it('should return -1 when the value is not present', function() {
      assert.equal(-1, [1, 2, 3].indexOf(4));
    });
  });
});