Skip to content
Snippets Groups Projects
Commit 9f5fec3d authored by Tore.Brede's avatar Tore.Brede
Browse files

Moving setup of i18n in testing to test-utils

parent 874a249d
No related branches found
No related tags found
1 merge request!111Improving testcase
Pipeline #96980 passed
...@@ -5,29 +5,20 @@ import AdapterDateFns from '@mui/lab/AdapterDateFns' ...@@ -5,29 +5,20 @@ import AdapterDateFns from '@mui/lab/AdapterDateFns'
import { LocalizationProvider } from '@mui/lab' import { LocalizationProvider } from '@mui/lab'
import Register from './index' import Register from './index'
// Mock react-i18next module to return a translation that just returns the key
jest.mock('react-i18next', () => ({
useTranslation: () => ({
t: (value: string) => value,
i18n: {
changeLanguage: () => new Promise(() => {
}),
},
}),
}))
test('Validation message showing if last name is missing', async () => { test('Validation message showing if last name is missing', async () => {
render( render(
<LocalizationProvider dateAdapter={AdapterDateFns}> <LocalizationProvider dateAdapter={AdapterDateFns}>
<Register /> <Register />
</LocalizationProvider>) </LocalizationProvider>
)
// Try to go to the next step and check that the validation message is showing // Try to go to the next step and check that the validation message is showing
const submitButton = screen.getByTestId('button-next') const submitButton = screen.getByTestId('button-next')
userEvent.click(submitButton) userEvent.click(submitButton)
const validationMessage = await waitFor(() => screen.getByText('validation.lastNameRequired')) const validationMessage = await waitFor(() =>
screen.getByText('validation.lastNameRequired')
)
expect(validationMessage).toBeInTheDocument() expect(validationMessage).toBeInTheDocument()
screen.queryByText('validation.lastNameRequired') screen.queryByText('validation.lastNameRequired')
...@@ -41,8 +32,9 @@ test('Validation message showing if last name is missing', async () => { ...@@ -41,8 +32,9 @@ test('Validation message showing if last name is missing', async () => {
screen.queryByText('validation.lastNameRequired') screen.queryByText('validation.lastNameRequired')
userEvent.click(submitButton) userEvent.click(submitButton)
await waitFor((() => { await waitFor(() => {
expect(screen.queryByText('validation.lastNameRequired')).not.toBeInTheDocument() expect(
})) screen.queryByText('validation.lastNameRequired')
).not.toBeInTheDocument()
})
}) })
...@@ -18,3 +18,13 @@ export * from '@testing-library/react' ...@@ -18,3 +18,13 @@ export * from '@testing-library/react'
// override render method // override render method
export { customRender as render } export { customRender as render }
// Mock react-i18next module to return a translation that just returns the key
jest.mock('react-i18next', () => ({
useTranslation: () => ({
t: (value: string) => value,
i18n: {
changeLanguage: () => new Promise(() => {}),
},
}),
}))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment