![]() ![]() Removes the mock and restores the initial implementation. You should therefore avoid assigning mockFn.mock to other variables, temporary or not, to make sure you don't access stale data. This is useful when you want to completely restore a mock back to its initial state.īeware that mockReset will replace mockFn.mock, not just and. Resets all information stored in the mock, including any initial implementation and mock name given. The clearMocks configuration option is available to clear mocks automatically between tests. Often this is useful when you want to clean up a mock's usage data between two assertions.īeware that mockClear will replace mockFn.mock, not just and. Resets all information stored in the and arrays. Each call is represented by an array of arguments that were passed during the call.įor example: A mock function f that has been called twice, with the arguments f('arg1', 'arg2'), and then with the arguments f('arg3', 'arg4') would have a mock.calls array that looks like this: [Īn array that contains all the object instances that have been instantiated from this mock function using new.įor example: A mock function that has been instantiated twice would have the following mock.instances array: const mockFn = jest.fn() Īn array that represents all calls that have been made into this mock function. Returns the mock name string set by calling mockFn.mockName(value). If no implementation is given, the mock function will return undefined when invoked. You can create a mock function with jest.fn(). Mock functions are also known as "spies", because they let you spy on the behavior of a function that is called indirectly by some other code, rather than only testing the output. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |