[英]Mocha ES6 tests supported?
I'm attempting to use expect tests with mocha , written in ES6, and am getting TypeError
even with a simple test case: 我正在尝试使用在ES6中编写的mocha的 expect测试,即使使用简单的测试用例,我也会得到
TypeError
:
import expect from "expect";
describe('Example', () => {
it('should just work', (done) => {
expect(5).to.eql(5);
done();
});
});
I'm using Babel to convert and run the tests: 我正在使用Babel转换并运行测试:
./node_modules/.bin/mocha --compilers js:babel/register example.js
Which results in: 结果如下:
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)
Is this not supported, or am I missing something critical? 这是不支持的,还是我错过了一些关键的东西?
Versions: 版本:
This was a head scratcher at first, but you're using importing the wrong expect! 起初这是一个令人头疼的问题,但你正在使用输入错误的期望!
Change your import to: 将导入更改为:
import expect from "expect.js";
And everything works. 一切正常。 Here is the
expect
module. 这是
expect
模块。 The module you're 'expect'ing to use is called expect.js
您期望使用的模块称为
expect.js
Hope this helps, and sorry for the bad pun :) 希望这会有所帮助,对不起的双关语抱歉:)
Edit: You'll also have to be sure to npm install expect.js
as well! 编辑:您还必须确保
npm install expect.js
!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.