Хотел перенести тестовый файл из jest в vitest, поэтому немного изменил код соответствующим образом, но столкнулся с ошибкой.
Я думаю, что сработает имитация макета хранилища, который я придумать не смог.
// SKIP_LOCALSTORAGE_CHECK
import React from 'react';
import { MockedProvider } from '@apollo/react-testing';
import {
act,
render,
screen,
fireEvent,
cleanup,
waitFor,
} from '@testing-library/react';
import userEvent from '@testing-library/user-event';
// import 'jest-localstorage-mock';
// import 'jest-location-mock';
import { I18nextProvider } from 'react-i18next';
import { Provider } from 'react-redux';
import { BrowserRouter } from 'react-router-dom';
import { store } from 'state/store';
import { StaticMockLink } from 'utils/StaticMockLink';
import i18nForTest from 'utils/i18nForTest';
import OrgList from './OrgList';
import {
MOCKS,
MOCKS_ADMIN,
MOCKS_EMPTY,
MOCKS_WITH_ERROR,
} from './OrgListMocks';
import { ToastContainer, toast } from 'react-toastify';
// jest.setTimeout(30000);
import useLocalStorage from 'utils/useLocalstorage';
import { vi } from 'vitest';
const { setItem } = useLocalStorage();
async function wait(ms = 100): Promise {
await act(() => {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
});
}
afterEach(() => {
localStorage.clear();
cleanup();
vi.clearAllMocks();
});
describe('Organisations Page testing as SuperAdmin', () => {
setItem('id', '123');
const link = new StaticMockLink(MOCKS, true);
const link2 = new StaticMockLink(MOCKS_EMPTY, true);
const link3 = new StaticMockLink(MOCKS_WITH_ERROR, true);
const formData = {
name: 'Dummy Organization',
description: 'This is a dummy organization',
address: {
city: 'Kingston',
countryCode: 'JM',
dependentLocality: 'Sample Dependent Locality',
line1: '123 Jamaica Street',
line2: 'Apartment 456',
postalCode: 'JM12345',
sortingCode: 'ABC-123',
state: 'Kingston Parish',
},
image: new File(['hello'], 'hello.png', { type: 'image/png' }),
};
test('Should display organisations for superAdmin even if admin For field is empty', async () => {
window.location.assign('/');
setItem('id', '123');
setItem('SuperAdmin', true);
setItem('AdminFor', []);
render(
,
);
await wait();
expect(
screen.queryByText('Organizations Not Found'),
).not.toBeInTheDocument();
});
});
Эта ошибка возникает, когда все тестовые примеры используют один и тот же здесь.
Я попробовал высмеивать vi.fn(), но не смог с этим справиться. put может ли кто-нибудь помочь мне с этим.
Хотел перенести тестовый файл из jest в vitest, поэтому немного изменил код соответствующим образом, но столкнулся с ошибкой. Я думаю, что сработает имитация макета хранилища, который я придумать не смог. [code]// SKIP_LOCALSTORAGE_CHECK import React from 'react'; import { MockedProvider } from '@apollo/react-testing'; import { act, render, screen, fireEvent, cleanup, waitFor, } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; // import 'jest-localstorage-mock'; // import 'jest-location-mock'; import { I18nextProvider } from 'react-i18next'; import { Provider } from 'react-redux'; import { BrowserRouter } from 'react-router-dom'; import { store } from 'state/store'; import { StaticMockLink } from 'utils/StaticMockLink'; import i18nForTest from 'utils/i18nForTest'; import OrgList from './OrgList';
import { MOCKS, MOCKS_ADMIN, MOCKS_EMPTY, MOCKS_WITH_ERROR, } from './OrgListMocks'; import { ToastContainer, toast } from 'react-toastify';
// jest.setTimeout(30000); import useLocalStorage from 'utils/useLocalstorage'; import { vi } from 'vitest';
describe('Organisations Page testing as SuperAdmin', () => { setItem('id', '123'); const link = new StaticMockLink(MOCKS, true); const link2 = new StaticMockLink(MOCKS_EMPTY, true); const link3 = new StaticMockLink(MOCKS_WITH_ERROR, true);
const formData = { name: 'Dummy Organization', description: 'This is a dummy organization', address: { city: 'Kingston', countryCode: 'JM', dependentLocality: 'Sample Dependent Locality', line1: '123 Jamaica Street', line2: 'Apartment 456', postalCode: 'JM12345', sortingCode: 'ABC-123', state: 'Kingston Parish', }, image: new File(['hello'], 'hello.png', { type: 'image/png' }), }; test('Should display organisations for superAdmin even if admin For field is empty', async () => { window.location.assign('/'); setItem('id', '123'); setItem('SuperAdmin', true); setItem('AdminFor', []);
render(
, );
await wait(); expect( screen.queryByText('Organizations Not Found'), ).not.toBeInTheDocument(); }); }); [/code] Эта ошибка возникает, когда все тестовые примеры используют один и тот же здесь. Я попробовал высмеивать vi.fn(), но не смог с этим справиться. put может ли кто-нибудь помочь мне с этим.