2012-07-02 17 views
1

每當我嘗試運行我的單元測試(用buster編寫並執行用戶buster test)幷包含jQuery(因爲我的庫依賴於它)。我得到以下錯誤:Buster.js jQuery依賴錯誤:未定義窗口

./test/deps/jquery-1.7.2.min.js: window is not defined

這是我的buster.js配置文件: 無功配置= module.exports;

config["GitJs Tests"] = { 
    rootPath: "../", 
    environment: "node", 
    sources: [ 
     "src/Gitjs.js" 
    ], 
    deps: [ 
     "test/deps/*.js" // Jquery is in here 
    ], 
    tests: [ 
     "test/test_constructor.js" 
    ] 
}; 

爲什麼我得到這個錯誤,我該如何解決?

回答

2

做了一些挖掘,並發現你會得到這個錯誤,因爲在Node中運行時,沒有窗口。 jQuery要求window對象正常工作。

簡而言之:您不能在NodeJs中使用jQuery(至少不能以其原生格式:D)。如果你想使用jQuery和busterJs,你需要在「瀏覽器」模式下運行它。