testdouble.js icon indicating copy to clipboard operation
testdouble.js copied to clipboard

td.reset causes doubles to have an identity crisis

Open jasonkarns opened this issue 7 years ago • 1 comments
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}

jasonkarns avatar Dec 21 '17 15:12 jasonkarns

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.

searls avatar Mar 24 '18 15:03 searls

Stale. Closing. Please reopen if still relevant and I will look into it.

giltayar avatar Sep 16 '23 11:09 giltayar