2014-09-23 57 views
1

我試圖用內實習生sinon-chai plugin,但它給了我:呼叫柴插件返回錯誤

Error {stack: (...), message: "Cannot find the Node.js require"} 

我已經安裝了通過NPM插件,這裏是我的測試文件:

define([ 
    'intern!bdd', 
    'intern/chai!expect', 
    'app/functions', 
    'intern/chai', 
    'intern/dojo/node!sinon-chai' 
], function (bdd, expect, myapp, chai, sinonChai) { 
    chai.use(sinonChai); 

    ... 

}); 

什麼可能會出錯?

+0

你browerified呢? – Vinz243 2014-09-23 14:18:14

回答

2

節點加載器需要Node.js,所以它不能在瀏覽器中使用。你需要直接加載興農柴庫,如下圖所示(從您的檢驗,假設以node_modules相對路徑是../node_modules):

define([ 
    'intern!bdd', 
    'intern/chai!expect', 
    'app/functions', 
    'intern/chai', 
    '../node_modules/sinon-chai/lib/sinon-chai' 
], function (bdd, expect, myapp, chai, sinonChai) { 
    chai.use(sinonChai); 
    ... 
}); 

您可以簡化測試包括通過定義興農釵包在您的實習配置:

... 
loader: { 
    { name: 'sinon-chai', location: 'node_modules/sinon-chai/lib' }, 
    ... 
} 
... 

然後,你可以用剛剛獲得通過:

define([ 
    ... 
    'sinon-chai/sinon-chai' 
], function (bed, expect, myapp, chai, sinonChai) { 
... 
}); 
+0

這就是我爲我的實習生安裝整合'chai-spies'庫的方式。有一點需要注意,我必須在我的package.json中單獨安裝chai lib,並在我的測試文件中包含node_modules文件夾中的chai lib以便使用'chai.use()'方法 – d48 2015-02-03 19:16:03