支持 Mocha ES6 测试吗?

Mocha ES6 tests supported?

我正在尝试使用 expect tests with mocha,用 ES6 编写,并且我得到 TypeError 即使是一个简单的测试用例:

import expect from "expect"; 

describe('Example', () => {
  it('should just work', (done) => {
    expect(5).to.eql(5);
    done();
  });
});

我正在使用 Babel 进行转换和 运行 测试:

./node_modules/.bin/mocha --compilers js:babel/register example.js

这导致:

  Example
    1) should just work


  0 passing (76ms)
  1 failing

  1) Example should just work:
     TypeError: Cannot read property 'eql' of undefined
      at Context.<anonymous> (example.js:5:17)

这是不支持的,还是我遗漏了一些重要的东西?

版本:

起初这让人头疼,但您使用的是导入错误的 expect!

将您的导入更改为:

import expect from "expect.js"; 

一切正常。 Hereexpect 模块。您“期望”使用的模块称为 expect.js

希望这对您有所帮助,对于不好的双关语,我们深表歉意:)

编辑:您还必须确保 npm install expect.js