Skip to content
This repository has been archived by the owner on May 7, 2021. It is now read-only.

Commit

Permalink
Added basic render test for HowDidItStartForm (#1509)
Browse files Browse the repository at this point in the history
* Added basic render test for HowDidItStartForm.
  • Loading branch information
naomiseminega authored Feb 24, 2020
1 parent 39e3ca2 commit 117b192
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions f2/src/forms/__tests__/HowDidItStartForm.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React from 'react'
import wait from 'waait'
import { i18n } from '@lingui/core'
import { render, fireEvent, cleanup } from '@testing-library/react'
import { MemoryRouter } from 'react-router-dom'
import { ThemeProvider } from 'emotion-theming'
import { I18nProvider } from '@lingui/react'
import en from '../../locales/en.json'
import canada from '../../theme/canada'
import { StateProvider, initialState, reducer } from '../../utils/state'
import { HowDidItStartForm } from '../HowDidItStartForm'

i18n.load('en', { en })
i18n.activate('en')

const clickOn = element => fireEvent.click(element)

describe('<HowDidItStartForm />', () => {
afterEach(cleanup)

it('calls the onSubmit function when the form is submitted', async () => {
const submitMock = jest.fn()

const { getByText } = render(
<MemoryRouter initialEntries={['/']}>
<ThemeProvider theme={canada}>
<I18nProvider i18n={i18n}>
<StateProvider initialState={initialState} reducer={reducer}>
<HowDidItStartForm onSubmit={submitMock} />
</StateProvider>
</I18nProvider>
</ThemeProvider>
</MemoryRouter>,
)

// we want to grab whatever is in the submit button as text, pass it to getByText
const context = document.querySelector('[type="submit"]').textContent
const nextButton = getByText(context)
clickOn(nextButton)
await wait(0) // Wait for promises to resolve

expect(submitMock).toHaveBeenCalledTimes(1)
})
})

0 comments on commit 117b192

Please sign in to comment.