import { render, screen } from '@testing-library/react' import { userEvent } from '@testing-library/user-event' import { mount } from 'enzyme' import toJson from 'enzyme-to-json' import { InitStepsErrors } from 'models/initialisationSteps.model' import React from 'react' import SplashScreenError from './SplashScreenError' describe('SplashScreenError component', () => { const reload = window.location.reload beforeAll(() => { Object.defineProperty(window, 'location', { value: { reload: jest.fn() }, }) }) afterAll(() => { window.location.reload = reload }) it('should be rendered correctly', () => { const component = mount( <SplashScreenError error={InitStepsErrors.CONSENT_ERROR} /> ) expect(toJson(component)).toMatchSnapshot() }) it('should reload the page', async () => { render(<SplashScreenError error={InitStepsErrors.CONSENT_ERROR} />) await userEvent.click(screen.getByRole('button')) expect(window.location.reload).toHaveBeenCalled() }) })