This repository has been archived by the owner on May 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added basic render test for HowDidItStartForm (#1509)
* Added basic render test for HowDidItStartForm.
- Loading branch information
1 parent
39e3ca2
commit 117b192
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
}) |