簡體   English   中英

支持Mocha ES6測試?

[英]Mocha ES6 tests supported?

我正在嘗試使用在ES6中編寫的mocha的 expect測試,即使使用簡單的測試用例,我也會得到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)

這是不支持的,還是我錯過了一些關鍵的東西?

版本:

  • babel 5.5.6
  • 期望1.6.0
  • 摩卡2.2.5

起初這是一個令人頭疼的問題,但你正在使用輸入錯誤的期望!

將導入更改為:

import expect from "expect.js"; 

一切正常。 expect模塊。 您期望使用的模塊稱為expect.js

希望這會有所幫助,對不起的雙關語抱歉:)

編輯:您還必須確保npm install expect.js

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM