testdouble.js
testdouble.js copied to clipboard
td.reset causes doubles to have an identity crisis
trafficstars
td.explain on a double after td.reset reports that it is not a double. It still is, and invoking the double still logs the call as expected. (And once the double is invoked after the reset, its explain is correct again.)
repro: https://jsfiddle.net/uto7uoq1/
foo = td.func('foo')
console.log(foo) // ƒ [test double for "foo"]
console.log(td.explain(foo)) // {name: "foo", callCount: 0, calls: Array(0), description: "This test double `foo` has 0 stubbings and 0 invocations.", isTestDouble: true}
td.reset() // this is critical; no reset == no bug
console.log(foo) // ƒ [test double for "foo"]
console.log(td.explain(foo)) // {name: undefined, callCount: 0, calls: Array(0), description: "This is not a test double.", isTestDouble: false}
foo('bar')
console.log(foo) // ƒ [test double for "foo"]
console.log(td.explain(foo)) // {name: undefined, callCount: 1, calls: Array(1), description: "This test double has 0 stubbings and 1 invocations.↵↵Invocations:↵ - called with `("bar")`.", isTestDouble: true}
I believe this will be fixed once the never-ending rewrite is done, because of the way the in-memory store persists its awareness of doubles.
Stale. Closing. Please reopen if still relevant and I will look into it.