Closed BruTyler closed 2 years ago
I've got a bug:
interface d { date: Date } let m = mock ({ date: new Date() })
m.date.getHours() //leads to TypeError: this is not a Date object at Proxy.getHours ()
Reason: Current get method of Proxy's handler loses its context: return obj[property]
Solving: Bind a context for the functions: return obj[property].bind(obj)
As a more specific solving: bind context only for Date's function
Did an example of solution: https://github.com/marchaos/jest-mock-extended/pull/60
Fixed in 2.0.4
I've got a bug:
interface d { date: Date } let m = mock ({
date: new Date()
})
m.date.getHours() //leads to TypeError: this is not a Date object at Proxy.getHours ()
Reason: Current get method of Proxy's handler loses its context: return obj[property]
Solving: Bind a context for the functions: return obj[property].bind(obj)
As a more specific solving: bind context only for Date's function