2014-08-28 70 views
1

編寫將通過瀏覽器加載到瀏覽器中的模塊。我試圖使用dojo/node插件來對模塊進行單元測試,但在嘗試加載單元測試時無法正常工作。我是否需要打包需要單元測試的模塊(即,在加載之前對它們進行瀏覽),還是有解決方法?通過實習生單元測試瀏覽器CommonJS模塊

規格:

define([ 
    'intern!object', 
    'intern/chai!assert', 
    'require', 
    // common css selectors 
    'intern/dojo/node!app/selectors' 
], function (
    registerSuite, 
    assert, 
    require, 
    SEL 
) { 

    registerSuite({ 

     name: 'Selectors Unit test', 

     'it is an object': function() { 
      assert.ok(typeof SEL === 'object', 
         'Selectors is an object'); 
     } 

    }); 

}); 

模塊:在http://localhost/node_modules/intern/client.html?config=tests/intern

錯誤給通過瀏覽器

module.exports = { 

    FOO : { _SELF: '#someId } 

}; 

跑步是Uncaught Error: Cannot find the Node.js require

是否在瀏覽器環境中的Dojo插件的工作?

回答

1

不,dojo/node將無法​​在瀏覽器中工作。作爲documentation指出的,

dojo/node只需訪問節點的天然require()函數,傳遞該插件參數作爲參數。