支持摩卡ES6测试? [英] Mocha ES6 tests supported?
问题描述
我正在尝试使用 进行测试与 mocha ,写在ES6中,即使有简单的测试用例,我也得到 TypeError
I'm attempting to use expect tests with mocha, written in ES6, and am getting TypeError
even with a simple test case:
import expect from "expect";
describe('Example', () => {
it('should just work', (done) => {
expect(5).to.eql(5);
done();
});
});
我正在使用Babel转换并运行测试:
I'm using Babel to convert and run the tests:
./ 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)
这不支持,还是我缺少一些关键的东西?
Is this not supported, or am I missing something critical?
版本:
- babel 5.5.6
- 期待1.6.0
- mocha 2.2.5
- babel 5.5.6
- expect 1.6.0
- mocha 2.2.5
推荐答案
这是一个头刮手,但是你正在使用导入错误的期望!
This was a head scratcher at first, but you're using importing the wrong expect!
将导入更改为:
import expect from "expect.js";
一切正常。 这里是 expect
模块。您期望使用的模块称为 expect.js
And everything works. Here is the expect
module. The module you're 'expect'ing to use is called expect.js
希望这有帮助,对不起对于坏的双关语:)
Hope this helps, and sorry for the bad pun :)
编辑:您还必须确保 npm install expect.js
以及
You'll also have to be sure to npm install expect.js
as well!
这篇关于支持摩卡ES6测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!