You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
it('Testa caso LocalStorage',async()=>{constemail={email: 'outro@trybe.com'};localStorage.setItem('user',JSON.stringify(email));jest.spyOn(Object.getPrototypeOf(global.localStorage),'getItem').mockReturnValue(JSON.stringify(email));renderWithRouterAndContext(<App/>,'/animal');awaitwaitFor(()=>expect(screen.getByText('DOGS VS CATS')).toBeInTheDocument());expect(global.alert).toHaveBeenCalledTimes(1);screen.getByText('outro@trybe.com');expect(localStorage.getItem).toHaveBeenCalled();});it('Testa caso não tenha LocalStorage',async()=>{jest.spyOn(Object.getPrototypeOf(global.localStorage),'getItem').mockReturnValue(JSON.stringify(''));renderWithRouterAndContext(<App/>,'/animal');awaitwaitFor(()=>expect(screen.getByText('DOGS VS CATS')).toBeInTheDocument());expect(global.alert).toHaveBeenCalledTimes(1);screen.getByText('não existe email');expect(localStorage.getItem).toHaveBeenCalled();});
Teste de Caso erro de fetch
it('Testa caso de erro',()=>{jest.spyOn(global,'fetch').mockRejectedValue(newError('DEU RUIM'));renderWithRouterAndContext(<App/>,'/animal');expect(requestApi()).rejects.toThrow(newError('Endpoint is required'));});