Funciones Mock
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. Puedes crear una falsa función con jest.fn()
. Si no se da la implementación, la función mockeda devolverá undefined
cuando se invoque.
info
Los ejemplos de TypeScript de esta página sólo funcionarán como documentados si se importan explícitamente APIs de Jest:
import {expect, jest, test} from '@jest/globals';
Consult the Getting Started guide for details on how to setup Jest with TypeScript.
Métodos
- Referencia
mockFn.getMockName()
mockFn.mock.calls
mockFn.mock.results
mockFn.mock.instances
mockFn.mock.contexts
mockFn.mock.lastCall
mockFn.mockClear()
mockFn.mockReset()
mockFn.mockRestore()
mockFn.mockImplementation(fn)
mockFn.mockImplementationOnce(fn)
mockFn.mockName(name)
mockFn.mockReturnThis()
mockFn.mockReturnValue(value)
mockFn.mockReturnValueOnce(value)
mockFn.mockResolvedValue(value)
mockFn.mockResolvedValueOnce(value)
mockFn.mockRejectedValue(value)
mockFn.mockRejectedValueOnce(value)
mockFn.withImplementation(fn, callback)
- Replaced Properties
- TypeScript Usage
Referencia
mockFn.getMockName()
Returns the mock name string set by calling .mockName()
.