【发布时间】:2012-11-05 06:42:48
【问题描述】:
我刚刚发现,如果我需要一个模块并将其存储为全局,我可以覆盖模块中的方法和属性,如下所示:
global.passwordhelper_mock = require("helpers/password")
sinon.stub(passwordhelper_mock, "checkPassword").returns true
如果我需要另一个本身使用上述存根方法的模块,则将使用我的存根版本。
node.js 中的require 函数如何注意到这些全局变量?为什么它仅在我覆盖/存根已保存为全局的模块时才有效?
谢谢
【问题讨论】:
标签: unit-testing node.js require