在测试过程中,我一直在收到有关行为的错误消息。
警告:测试中没有对EmployeesDashboard进行更新 包裹在act(...)中。
When testing,code that causes React state updates should be wrapped into act(...): act(() => { /* fire events that update state */ }); /* assert on the output */ in EmployeesDashboard (at EmployeesDashboard.test.tsx:69)"
我不知道为什么,因为似乎我已经将所有内容都包装在表演中了...在这里我也应该包装在表演中呢?由于我是测试的新手,所以将不胜感激。
import React from 'react';
import { mocked } from 'ts-jest/utils';
import { act } from 'react-dom/test-utils';
import { EmployeesDashboard } from '../EmployeesDashboard';
import {
render,wait,waitForElementToberemoved,} from '@testing-library/react';
import { Employee } from '@neurocann-ui/types';
import { getall } from '@neurocann-ui/api';
jest.mock('@neurocann-ui/api');
const fakeEmployees: Employee[] = [
{
email: 'joni@gmail.com',phone: '720-555-555',mailingAddress: {
type: 'home',streetOne: '390 Blake St',streetTwo: 'Apt 11',city: 'Denver',state: 'CO',zip: '90203',},name: 'Joni Baez',permissions: ['Employee'],hireDate: new Date('2020-09-19T05:13:12.923Z'),{
email: 'joni22@gmail.com',];
mocked(getall).mockImplementation(
(): Promise<any> => {
return Promise.resolve({ data: fakeEmployees });
},);
describe('EmployeesDashboard',() => {
it('renders progress loader',() => {
act(() => {
render(<EmployeesDashboard />)
});
const employeesDashboard = document.getElementById(
'simple-circular-progress',);
expect(employeesDashboard).toBeInTheDocument();
expect(employeesDashboard).toMatchsnapshot();
});
it('renders a table',async () => {
await act(() => { render(<EmployeesDashboard />) });
const table = document.getElementById('employees-table');
expect(table).toBeInTheDocument();
});
});