Tengo el siguiente método que funciona. Estoy tratando de escribir una prueba para ello.
¿Cómo podría burlarme de window.getStatus para devolver los valores en la cadena para poder burlarme de un valor de retorno?
y también poder validar que la Cadena se llamó con el valor correcto?
import get from 'lodash/get'; const getData = (name) => get(window.getStatus(), `data.toJS()[\'base-path\'].current[\'${name}'].exclusions[\'period\']`);Intenté la siguiente prueba.
Pero arroja este error.
TypeError: window.getStatus no es una función
Prueba
describe('My Test', () => { let windowSpy; beforeEach(() => { windowSpy = jest.spyOn(window, "window", "get"); }); afterEach(() => { windowSpy.mockRestore(); }); it('should ', () => { windowSpy.mockImplementation(() => ({ getStatus: { data: { 'base-path': { current: { 'login-name': { exclusions: { 'period': 'mock name', } } } } } } })); const result = getData('login-name'); expect(result).toEqual('mock name'); }); });