diff --git a/src/components/ButtonsToolbar/test.spec.jsx b/src/components/ButtonsToolbar/test.spec.jsx index eefa0d0e2..46f0ab835 100644 --- a/src/components/ButtonsToolbar/test.spec.jsx +++ b/src/components/ButtonsToolbar/test.spec.jsx @@ -45,7 +45,7 @@ const Wrap = ({children}) => ( ); it('Last step of submittable form, button is present', () => { - const mockFunction = jest.fn(); + const mockFunction = vi.fn(); act(() => { root.render( @@ -76,7 +76,7 @@ it('Last step of submittable form, button is present', () => { }); it('Last step of non-submittable form with overview, button is present', () => { - const mockFunction = jest.fn(); + const mockFunction = vi.fn(); act(() => { root.render( @@ -107,7 +107,7 @@ it('Last step of non-submittable form with overview, button is present', () => { }); it('Last step of non-submittable form without overview, button is NOT present', () => { - const mockFunction = jest.fn(); + const mockFunction = vi.fn(); act(() => { root.render( @@ -137,7 +137,7 @@ it('Last step of non-submittable form without overview, button is NOT present', }); it('Non-last step of non-submittable form without overview, button IS present', () => { - const mockFunction = jest.fn(); + const mockFunction = vi.fn(); act(() => { root.render( @@ -168,7 +168,7 @@ it('Non-last step of non-submittable form without overview, button IS present', }); it('Suspending form allowed, button is present', () => { - const mockFunction = jest.fn(); + const mockFunction = vi.fn(); renderTest( @@ -191,7 +191,7 @@ it('Suspending form allowed, button is present', () => { }); it('Suspending form not allowed, button is NOT present', () => { - const mockFunction = jest.fn(); + const mockFunction = vi.fn(); renderTest( diff --git a/src/components/Form.spec.jsx b/src/components/Form.spec.jsx index c57f70faf..b061d4ebc 100644 --- a/src/components/Form.spec.jsx +++ b/src/components/Form.spec.jsx @@ -12,7 +12,7 @@ import {routes} from 'components/App'; import {START_FORM_QUERY_PARAM} from './constants'; -window.scrollTo = jest.fn(); +window.scrollTo = vi.fn(); beforeEach(() => { localStorage.clear(); @@ -23,7 +23,7 @@ afterEach(() => { }); afterAll(() => { - jest.clearAllMocks(); + vi.clearAllMocks(); }); const Wrapper = ({form = buildForm(), initialEntry = '/startpagina'}) => { diff --git a/src/components/FormStart/tests.spec.jsx b/src/components/FormStart/tests.spec.jsx index 72ab89450..3be396035 100644 --- a/src/components/FormStart/tests.spec.jsx +++ b/src/components/FormStart/tests.spec.jsx @@ -10,8 +10,8 @@ import useQuery from 'hooks/useQuery'; import FormStart from '.'; import {testForm, testLoginForm} from './fixtures'; -jest.mock('hooks/useQuery'); -let scrollIntoViewMock = jest.fn(); +vi.mock('hooks/useQuery'); +let scrollIntoViewMock = vi.fn(); window.HTMLElement.prototype.scrollIntoView = scrollIntoViewMock; const Wrap = ({children}) => ( @@ -24,8 +24,8 @@ it('Form start page start if _start parameter is present', async () => { const testLocation = new URLSearchParams('?_start=1'); useQuery.mockReturnValue(testLocation); - const onFormStart = jest.fn(); - const onDestroySession = jest.fn(); + const onFormStart = vi.fn(); + const onDestroySession = vi.fn(); render( @@ -55,8 +55,8 @@ it.each([ ])( 'Form start does not start if there are auth errors / %s', async (testQuery, expectedMessage) => { - const onFormStart = jest.fn(); - const onDestroySession = jest.fn(); + const onFormStart = vi.fn(); + const onDestroySession = vi.fn(); const testLocation = new URLSearchParams(`?_start=1&${testQuery}`); useQuery.mockReturnValue(testLocation); @@ -74,8 +74,8 @@ it.each([ it('Form start page does not show login buttons if an active submission is present', async () => { useQuery.mockReturnValue(new URLSearchParams()); - const onFormStart = jest.fn(); - const onDestroySession = jest.fn(); + const onFormStart = vi.fn(); + const onDestroySession = vi.fn(); render( @@ -95,8 +95,8 @@ it('Form start page does not show login buttons if an active submission is prese it('Form start page with initial_data_reference', async () => { useQuery.mockReturnValue(new URLSearchParams()); - const onFormStart = jest.fn(); - const onDestroySession = jest.fn(); + const onFormStart = vi.fn(); + const onDestroySession = vi.fn(); render( diff --git a/src/components/LoginOptions/tests.spec.jsx b/src/components/LoginOptions/tests.spec.jsx index 1e947afbe..8da223d7e 100644 --- a/src/components/LoginOptions/tests.spec.jsx +++ b/src/components/LoginOptions/tests.spec.jsx @@ -36,7 +36,7 @@ const Wrapper = ({form, onFormStart}) => { it('Login not required, options wrapped in form tag', async () => { const user = userEvent.setup(); const form = buildForm({loginRequired: false, loginOptions: [], cosignLoginOptions: []}); - const onFormStart = jest.fn(e => e.preventDefault()); + const onFormStart = vi.fn(e => e.preventDefault()); render(); @@ -69,7 +69,7 @@ it('Login required, options not wrapped in form tag', async () => { ], cosignLoginOptions: [], }); - const onFormStart = jest.fn(e => e.preventDefault()); + const onFormStart = vi.fn(e => e.preventDefault()); const {location} = window; delete window.location; @@ -112,7 +112,7 @@ it('Login button has the right URL after cancelling log in', async () => { cosignLoginOptions: [], }); - const onFormStart = jest.fn(e => e.preventDefault()); + const onFormStart = vi.fn(e => e.preventDefault()); const {location} = window; delete window.location; diff --git a/src/components/Summary/test.spec.jsx b/src/components/Summary/test.spec.jsx index 70191e9f0..bc8b07887 100644 --- a/src/components/Summary/test.spec.jsx +++ b/src/components/Summary/test.spec.jsx @@ -31,8 +31,8 @@ const SUBMISSION = { isAuthenticated: false, }; -jest.mock('react-use'); -jest.mock('hooks/useRefreshSubmission'); +vi.mock('react-use'); +vi.mock('hooks/useRefreshSubmission'); let container = null; let root = null; @@ -64,8 +64,8 @@ it('Summary displays logout button if isAuthenticated is true', () => { ...SUBMISSION, isAuthenticated: true, }; - const onDestroySession = jest.fn(); - const onConfirm = jest.fn(); + const onDestroySession = vi.fn(); + const onConfirm = vi.fn(); useAsync.mockReturnValue({loading: false, value: []}); useRefreshSubmission.mockReturnValue(submissionIsAuthenticated); @@ -92,8 +92,8 @@ it('Summary does not display logout button if loginRequired is false', () => { ...testForm, loginRequired: false, }; - const onDestroySession = jest.fn(); - const onConfirm = jest.fn(); + const onDestroySession = vi.fn(); + const onConfirm = vi.fn(); useAsync.mockReturnValue({loading: false, value: []}); useRefreshSubmission.mockReturnValue({...SUBMISSION, isAuthenticated: false}); @@ -116,8 +116,8 @@ it('Summary does not display logout button if loginRequired is false', () => { }); it('Summary displays abort button if isAuthenticated is false', () => { - const onDestroySession = jest.fn(); - const onConfirm = jest.fn(); + const onDestroySession = vi.fn(); + const onConfirm = vi.fn(); useAsync.mockReturnValue({loading: false, value: []}); useRefreshSubmission.mockReturnValue({...SUBMISSION, isAuthenticated: false}); diff --git a/src/components/SummaryConfirmation/test.spec.jsx b/src/components/SummaryConfirmation/test.spec.jsx index f0deea168..ec086a9e8 100644 --- a/src/components/SummaryConfirmation/test.spec.jsx +++ b/src/components/SummaryConfirmation/test.spec.jsx @@ -39,7 +39,7 @@ const Wrapper = ({children}) => ( {children} @@ -48,7 +48,7 @@ const Wrapper = ({children}) => ( ); it('Summary of non-submittable form, button is NOT present', () => { - const mockFunction = jest.fn(); + const mockFunction = vi.fn(); renderTest( @@ -66,7 +66,7 @@ it('Summary of non-submittable form, button is NOT present', () => { }); it('Summary of submittable form, button IS present', () => { - const mockFunction = jest.fn(); + const mockFunction = vi.fn(); renderTest( diff --git a/src/components/appointments/CreateAppointment/CreateAppointment.spec.jsx b/src/components/appointments/CreateAppointment/CreateAppointment.spec.jsx index 1c7143328..4f0c9998e 100644 --- a/src/components/appointments/CreateAppointment/CreateAppointment.spec.jsx +++ b/src/components/appointments/CreateAppointment/CreateAppointment.spec.jsx @@ -24,8 +24,8 @@ import { } from '../mocks'; import {SESSION_STORAGE_KEY as APPOINTMENT_SESSION_STORAGE_KEY} from './CreateAppointmentState'; -// scrollIntoView is not not supported in Jest -let scrollIntoViewMock = jest.fn(); +// scrollIntoView is not not supported in jest-dom +let scrollIntoViewMock = vi.fn(); window.HTMLElement.prototype.scrollIntoView = scrollIntoViewMock; const routes = [ diff --git a/src/components/appointments/CreateAppointment/Summary.spec.jsx b/src/components/appointments/CreateAppointment/Summary.spec.jsx index 9e4a19f4c..efaf979ab 100644 --- a/src/components/appointments/CreateAppointment/Summary.spec.jsx +++ b/src/components/appointments/CreateAppointment/Summary.spec.jsx @@ -1,4 +1,3 @@ -import {jest} from '@jest/globals'; import {render as realRender, screen, waitFor} from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import messagesEN from 'i18n/compiled/en.json'; @@ -164,7 +163,7 @@ describe('The appointment summary', () => { it('processes backend validation errors', async () => { mswServer.use(mockAppointmentErrorPost); const user = userEvent.setup({delay: null}); - const errorHandler = jest.fn(); + const errorHandler = vi.fn(); renderSummary(errorHandler); diff --git a/src/components/appointments/fields/DateSelect.spec.jsx b/src/components/appointments/fields/DateSelect.spec.jsx index e34ebba4a..670434a56 100644 --- a/src/components/appointments/fields/DateSelect.spec.jsx +++ b/src/components/appointments/fields/DateSelect.spec.jsx @@ -1,4 +1,3 @@ -import {jest} from '@jest/globals'; import {act, render as realRender, screen, waitFor} from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import {Formik} from 'formik'; @@ -41,15 +40,15 @@ const render = (comp, locationId) => ); beforeEach(() => { - jest.useFakeTimers({ + vi.useFakeTimers({ advanceTimers: true, now: new Date('2023-06-12T14:00:00Z'), }); }); afterEach(() => { - jest.runOnlyPendingTimers(); - jest.useRealTimers(); + vi.runOnlyPendingTimers(); + vi.useRealTimers(); }); describe('The appointment date select', () => { diff --git a/src/components/appointments/fields/TimeSelect.spec.jsx b/src/components/appointments/fields/TimeSelect.spec.jsx index 998e1511a..49cda6606 100644 --- a/src/components/appointments/fields/TimeSelect.spec.jsx +++ b/src/components/appointments/fields/TimeSelect.spec.jsx @@ -1,4 +1,3 @@ -import {jest} from '@jest/globals'; import {act, render as realRender, screen, waitFor} from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import {Formik} from 'formik'; @@ -39,15 +38,15 @@ const render = (comp, locationId) => ); beforeEach(() => { - jest.useFakeTimers({ + vi.useFakeTimers({ advanceTimers: true, now: new Date('2023-06-12T14:00:00Z'), }); }); afterEach(() => { - jest.runOnlyPendingTimers(); - jest.useRealTimers(); + vi.runOnlyPendingTimers(); + vi.useRealTimers(); }); describe('The appointment time select', () => { diff --git a/src/components/appointments/steps/LocationAndTimeStep.spec.jsx b/src/components/appointments/steps/LocationAndTimeStep.spec.jsx index daf42d0bd..efe4d3363 100644 --- a/src/components/appointments/steps/LocationAndTimeStep.spec.jsx +++ b/src/components/appointments/steps/LocationAndTimeStep.spec.jsx @@ -1,4 +1,3 @@ -import {jest} from '@jest/globals'; import {act, render as realRender, screen, waitFor} from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import messagesEN from 'i18n/compiled/en.json'; @@ -59,15 +58,15 @@ const render = initialValues => { }; beforeEach(() => { - jest.useFakeTimers({ + vi.useFakeTimers({ advanceTimers: true, now: new Date('2023-06-12T14:00:00Z'), }); }); afterEach(() => { - jest.runOnlyPendingTimers(); - jest.useRealTimers(); + vi.runOnlyPendingTimers(); + vi.useRealTimers(); window.sessionStorage.clear(); }); diff --git a/src/components/auth/AuthenticationErrors/tests.spec.jsx b/src/components/auth/AuthenticationErrors/tests.spec.jsx index 5fd2a7e25..ea26fb4ad 100644 --- a/src/components/auth/AuthenticationErrors/tests.spec.jsx +++ b/src/components/auth/AuthenticationErrors/tests.spec.jsx @@ -6,7 +6,7 @@ import {IntlProvider} from 'react-intl'; import {AuthenticationErrors} from '.'; -let scrollIntoViewMock = jest.fn(); +let scrollIntoViewMock = vi.fn(); window.HTMLElement.prototype.scrollIntoView = scrollIntoViewMock; let container = null; diff --git a/src/jstests/formio/components/date.spec.js b/src/jstests/formio/components/date.spec.js index b9ce0b14b..c393ec884 100644 --- a/src/jstests/formio/components/date.spec.js +++ b/src/jstests/formio/components/date.spec.js @@ -110,12 +110,12 @@ describe('Date Component', () => { }, }; - const mockTranslation = jest.fn((message, values) => message); + const mockTranslation = vi.fn((message, values) => message); const componentInstance = new FormioComponent(component, {}, {}); componentInstance.t = mockTranslation; componentInstance.options.intl = { - formatDate: jest.fn((date, options) => 'formatted date'), + formatDate: vi.fn((date, options) => 'formatted date'), }; set( diff --git a/src/jstests/formio/components/datetime.spec.js b/src/jstests/formio/components/datetime.spec.js index 2ea46ff7c..5bee2b172 100644 --- a/src/jstests/formio/components/datetime.spec.js +++ b/src/jstests/formio/components/datetime.spec.js @@ -150,12 +150,12 @@ describe('Datetime Component', () => { }, }; - const mockTranslation = jest.fn((message, values) => message); + const mockTranslation = vi.fn((message, values) => message); const componentInstance = new FormioComponent(component, {}, {}); componentInstance.t = mockTranslation; componentInstance.options.intl = { - formatDate: jest.fn((date, options) => 'formatted date'), + formatDate: vi.fn((date, options) => 'formatted date'), }; set( diff --git a/src/sdk.spec.jsx b/src/sdk.spec.jsx index f4a193b43..5237f4d56 100644 --- a/src/sdk.spec.jsx +++ b/src/sdk.spec.jsx @@ -6,8 +6,8 @@ import {mockFormioTranslations, mockLanguageInfoGet} from 'components/LanguageSe import {OpenForm} from './sdk'; -// scrollIntoView is not supported in Jest -let scrollIntoViewMock = jest.fn(); +// scrollIntoView is not supported in jest-dom +let scrollIntoViewMock = vi.fn(); window.HTMLElement.prototype.scrollIntoView = scrollIntoViewMock; const LANGUAGES = [ @@ -123,7 +123,7 @@ describe('OpenForm', () => { mswServer.use(...apiMocks); const formRoot = document.createElement('div'); const target = document.createElement('div'); - const onLanguageChangeMock = jest.fn(); + const onLanguageChangeMock = vi.fn(); const form = new OpenForm(formRoot, { baseUrl: BASE_URL,