4
我正在嘗試測試模塊中的功能。這個函數(我將它稱爲function_a)在同一個文件中調用一個不同的函數(function_b)。所以這個模塊看起來像這樣:nodejs覆蓋模塊中的功能
//the module file
module.exports.function_a = function(){
//does stuff
function_b()
};
module.exports.function_b = function_b = function() {
//more stuff
}
我需要使用function_b的特定結果來測試function_a。
我想從我的測試文件中覆蓋function_b,然後從我的測試文件中調用function_a,導致function_a調用這個覆蓋函數而不是function_b。
剛一說明,我已經嘗試併成功地從獨立的模塊壓倒一切的功能,如this的問題,但是這不是我感興趣的
我曾嘗試下面的代碼,並儘量據我所知,這是行不通的。它確實說明了我要去的,但。
//test file
that_module = require("that module")
that_module.function_b = function() { ...override ... }
that_module.function_a() //now uses the override function
有沒有正確的方法來做到這一點?
完美的工作!萬分感謝! – 2014-09-03 16:30:48