Returns current permanent mock implementation if there is one.
If mock was created with vi.fn, it will consider passed down method as a mock implementation.
If mock was created with vi.spyOn, it will return undefined unless a custom implementation was provided.
Use it to return the name assigned to the mock with the .mockName(name) method. By default, it will return vi.fn().
Clears all information about every call. After calling it, all properties on .mock will return to their initial state. This method does not reset implementations. It is useful for cleaning up mocks between different assertions.
To automatically call this method before each test, enable the clearMocks setting in the configuration.
Accepts a function to be used as the mock implementation. TypeScript expects the arguments and return type to match those of the original function.
Accepts a function to be used as the mock implementation. TypeScript expects the arguments and return type to match those of the original function. This method can be chained to produce different results for multiple function calls.
When the mocked function runs out of implementations, it will invoke the default implementation set with vi.fn(() => defaultValue) or .mockImplementation(() => defaultValue) if they were called.
Sets the internal mock name. This is useful for identifying the mock when an assertion fails.
Accepts a value that will be rejected during the next function call. If chained, each consecutive call will reject the specified value.
Does what mockClear does and resets inner implementation to the original function. This also resets all "once" implementations.
Note that resetting a mock from vi.fn() will set implementation to an empty function that returns undefined.
Resetting a mock from vi.fn(impl) will set implementation to impl. It is useful for completely resetting a mock to its default state.
To automatically call this method before each test, enable the mockReset setting in the configuration.
Accepts a value that will be resolved when the async function is called. TypeScript will only accept values that match the return type of the original function.
Accepts a value that will be resolved during the next function call. TypeScript will only accept values that match the return type of the original function. If chained, each consecutive call will resolve the specified value.
Does what mockReset does and restores original descriptors of spied-on objects.
Use this if you need to return the this context from the method without invoking the actual implementation.
Accepts a value that will be returned whenever the mock function is called. TypeScript will only accept values that match the return type of the original function.
Accepts a value that will be returned whenever the mock function is called. TypeScript will only accept values that match the return type of the original function.
When the mocked function runs out of implementations, it will invoke the default implementation set with vi.fn(() => defaultValue) or .mockImplementation(() => defaultValue) if they were called.
Overrides the original mock implementation temporarily while the callback is being executed.
Note that this method takes precedence over the mockImplementationOnce.
Current context of the mock. It stores information about all invocation calls, instances, and results.