Skip to content
Snippets Groups Projects
SplashScreenError.spec.tsx 1.03 KiB
Newer Older
  • Learn to ignore specific revisions
  • Bastien DUMONT's avatar
    Bastien DUMONT committed
    import { render, screen } from '@testing-library/react'
    import { userEvent } from '@testing-library/user-event'
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    import { mount } from 'enzyme'
    
    import toJson from 'enzyme-to-json'
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    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()
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
      it('should reload the page', async () => {
        render(<SplashScreenError error={InitStepsErrors.CONSENT_ERROR} />)
        await userEvent.click(screen.getByRole('button'))
    
        expect(window.location.reload).toHaveBeenCalled()
      })
    })