Skip to content

Instantly share code, notes, and snippets.

@kopax
Last active February 2, 2021 15:33
Show Gist options
  • Save kopax/69ea35181d55593f8b3a51938e359ef4 to your computer and use it in GitHub Desktop.
Save kopax/69ea35181d55593f8b3a51938e359ef4 to your computer and use it in GitHub Desktop.
import { renderHook } from '@testing-library/react-hooks'
import { fireEvent, render } from '@testing-library/react-native'
import React from 'react'
import { ForgottenPassword } from 'features/auth/forgottenPassword/ForgottenPassword'
import { queryCache, reactQueryProviderHOC } from 'tests/reactQueryProviderHOC'
beforeEach(() => {
jest.resetAllMocks()
})
async function afterHack() {
const { waitFor } = renderHook(() => null)
await waitFor(() => {
if (queryCache.isFetching) {
throw new Error('The react-query queryCache is still fetching')
}
})
}
describe('<ForgottenPassword />', () => {
beforeEach(() => {
queryCache.clear({ notify: false })
})
afterEach(() => {
afterHack()
})
it.only('should redirect to ResetPasswordEmailSent when password reset request is successful', async () => {
const { getByPlaceholderText, findByText } = renderPage()
const emailInput = getByPlaceholderText('tonadresse@email.com')
fireEvent.changeText(emailInput, 'john.doe@gmail.com')
const validateEmailButton = await findByText('Valider')
fireEvent.press(validateEmailButton) // <==== line that break
})
})
function renderPage() {
return render(reactQueryProviderHOC(<ForgottenPassword />))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment