Skip to content
Snippets Groups Projects
ChallengeCardLast.spec.tsx 882 B
Newer Older
  • Learn to ignore specific revisions
  • import { act, render, screen } from '@testing-library/react'
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    import { userEvent } from '@testing-library/user-event'
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    import React from 'react'
    import ChallengeCardLast from './ChallengeCardLast'
    
    // Value coming from jest.config
    declare let __SAU_IDEA_DIRECT_LINK__: string
    
    
    describe('ChallengeCardLast component', () => {
    
      it('should be rendered correctly', () => {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        const { container } = render(<ChallengeCardLast />)
        expect(container).toMatchSnapshot()
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
      it('should open SAU new idea link', async () => {
    
        global.open = jest.fn()
    
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        render(<ChallengeCardLast />)
    
        await act(async () => {
          await userEvent.click(screen.getByText('challenge.card_last.button'))
        })
    
        expect(window.open).toHaveBeenCalledTimes(1)
    
        expect(global.open).toHaveBeenCalledWith(
          `${__SAU_IDEA_DIRECT_LINK__}?version=0.0.0`
        )
      })