【发布时间】:2023-03-06 10:35:01
【问题描述】:
在 js 测试中,我无法理解 Spy-Spies 的概念以及与 stubs 的区别。
间谍:
function spyOn(Object, method) { /*... */ }
// A common way of using a spy
const dateSpy = spyOn(Date, 'now')
Date.now()
// A common way of checking the spy
console.log(dateSpy.called.length > 0)
存根:
function stubAmount(amount) {
Apple.amount = () => amount
}
// Testing function
function haveApple(amount) {
stubAmount(amount)
howsMyCollection()
}
【问题讨论】:
标签: javascript unit-testing tdd end-to-end