¿Cómo escribir el caso de prueba para la siguiente función? Lo esperado es: si se proporciona SuccessPath, entonces onSignInSuccess debería redirigirlo a SuccessPath
export const onSignInSuccess = ( data ) => { return ( ) => { global.location.href = data?.detail?.data?.successPath; } }Lo que he intentado hasta ahora es pero no funciona
const data = { detail : { data: { redirectPage: true, successPath: 'test.com' } } } onSignInSuccess( data )() expect( jest.fn() ).toHaveBeenCalledWith( 'test.com' )Encontré la solución burlándome de window.location.href
it( 'should redirect to successPath if given', ()=>{ global.window = Object.create( window ); const url = 'http://test.com'; Object.defineProperty( window, 'location', { value: { href: url } } ); const data = { detail : { data: { redirectPage: true, successPath: 'test.com' } } } onSignInSuccess( data )() expect( global.location.href ).toBe( 'test.com' ) } );