In Jest testing framework, there is a jest.genMockFn() function that create object which can be called as function and simultaneously accessing it's properties.
var mockFn = jest.genMockFn()
mockFn('Hello world!')
mockFn('The world is yours.')
console.log(mockFn.mock.calls) // [["Hello world!"], ["The world is yours."]]
When I dump mockFn i get:
{ [Function]
_isMockFunction: true,
mock:
{ calls: [ [Object], [Object] ],
instances: [ [Object], [Object] ] },
mockClear: [Function],
mockReturnValueOnce: [Function],
mockReturnValue: [Function],
mockImpl: [Function],
mockImplementation: [Function],
mockReturnThis: [Function],
_getMockImplementation: [Function] }
I can't figure out how they achieve this. Any ideas? Can you provide code with similar functionality? Thank you.