支持Mocha ES6测试?

Col*_*len 7 javascript mocha.js ecmascript-6

我正在尝试使用在ES6中编写的mocha的expect测试,并且即使使用简单的测试用例也是如此:TypeError

import expect from "expect"; 

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

我正在使用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)
Run Code Online (Sandbox Code Playgroud)

这是不支持的,还是我错过了一些关键的东西?

版本:

  • babel 5.5.6
  • 期望1.6.0
  • 摩卡2.2.5

Bre*_*nan 8

起初这是一个令人头疼的问题,但你正在使用输入错误的期望!

将导入更改为:

import expect from "expect.js"; 
Run Code Online (Sandbox Code Playgroud)

一切正常. expect模块.您希望使用的模块被调用expect.js

希望这会有所帮助,对不起的双关语抱歉:)

编辑:你也必须确保npm install expect.js!