2016-02-26 49 views
4

綜觀其他問題,無法真正找到問題的原因。我正在嘗試導入一個模塊並使用摩卡進行測試。確保完成()回調被稱爲在這個測試(摩卡,柴,興農)

import chai, { 
    expect 
} 
from 'chai'; 
import sinon from 'sinon'; 
import sinonChai from 'sinon-chai'; 
import System from 'systemjs'; 
import '../public/config.js'; 

chai.use(sinonChai); 

describe('helperModule',() => { 
    let module; 

    before(function() { 
     return System.import('./public/js/helper.js') 
      .then((mod) => module = mod); 
    }); 

    describe('Module loading', function() { 
     it('should load', function(){ 
      expect(module.default).to.not.be.undefined; 
     }); 
    }); 
}); 

我運行npm test命令時出現以下錯誤。

1) helperModule "before all" hook: 
    Error: timeout of 2000ms exceeded. Ensure the done() callback is being 
called in this test. 

不確定在哪裏完成回調。如果您需要關於我正在使用的任何軟件包的任何額外信息,我將與他們一起編輯我的問題。

回答

7

有一個期望,當你的測試完成一個做()調用回調函數。有些圖書館爲你隱式地做這件事,你也可以將其他功能傳遞給成功的其他功能。如果需要手動完成,可以將done指定爲稍後調用的測試函數的參數。

describe('Module loading', function() { 
    it('should load', function(done){ 
     expect(module.default).to.not.be.undefined; 
     done(); 
    }); 
}); 
+0

我現在正在收到另一個錯誤,我想我只好讓它刷新測試。任何想法與這一個?無法讀取未定義 \t評價文件的特性「的createElement」:///jspm_packages/npm/[email protected]/dist/jquery.js –

+0

我將關閉這個問題,將其標記爲解決 –