chore: make testing more stable
This commit is contained in:
parent
880f7ed7e4
commit
e7ade9ee12
@ -1,5 +1,5 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { fireEvent, render, screen, sleep, userEvent } from 'testUtils';
|
import { fireEvent, render, screen, userEvent, waitFor } from 'testUtils';
|
||||||
import App1 from '../demos/demo1';
|
import App1 from '../demos/demo1';
|
||||||
import App2 from '../demos/demo2';
|
import App2 from '../demos/demo2';
|
||||||
|
|
||||||
@ -33,8 +33,9 @@ describe('Cascader', () => {
|
|||||||
|
|
||||||
// 因为是异步加载,所以需要等待一下
|
// 因为是异步加载,所以需要等待一下
|
||||||
expect(screen.queryByText('Zhejiang Dynamic 1')).not.toBeInTheDocument();
|
expect(screen.queryByText('Zhejiang Dynamic 1')).not.toBeInTheDocument();
|
||||||
await sleep(300);
|
await waitFor(() => {
|
||||||
expect(screen.getByText('Zhejiang Dynamic 1')).toBeInTheDocument();
|
expect(screen.getByText('Zhejiang Dynamic 1')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
fireEvent.click(screen.getByText('Zhejiang Dynamic 1'));
|
fireEvent.click(screen.getByText('Zhejiang Dynamic 1'));
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { render, screen, sleep, userEvent, waitFor } from 'testUtils';
|
import { render, screen, userEvent, waitFor } from 'testUtils';
|
||||||
import App1 from '../demos/demo1';
|
import App1 from '../demos/demo1';
|
||||||
import App2 from '../demos/demo2';
|
import App2 from '../demos/demo2';
|
||||||
import App3 from '../demos/demo3';
|
import App3 from '../demos/demo3';
|
||||||
@ -17,10 +17,10 @@ describe('FormV2', () => {
|
|||||||
await userEvent.type(input, '李四');
|
await userEvent.type(input, '李四');
|
||||||
await userEvent.click(submit);
|
await userEvent.click(submit);
|
||||||
|
|
||||||
await sleep(100);
|
await waitFor(() => {
|
||||||
|
// notification 的内容
|
||||||
// notification 的内容
|
expect(screen.getByText(/\{"nickname":"李四"\}/i)).toBeInTheDocument();
|
||||||
expect(screen.getByText(/\{"nickname":"李四"\}/i)).toBeInTheDocument();
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('initial values', async () => {
|
it('initial values', async () => {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { render, sleep } from 'testUtils';
|
import { render, waitFor } from 'testUtils';
|
||||||
import App1 from '../demos/demo1';
|
import App1 from '../demos/demo1';
|
||||||
|
|
||||||
// jsdom does not support canvas, so we need to skip this test
|
// jsdom does not support canvas, so we need to skip this test
|
||||||
@ -7,9 +7,9 @@ describe.skip('G2Plot', () => {
|
|||||||
it('basic', async () => {
|
it('basic', async () => {
|
||||||
render(<App1 />);
|
render(<App1 />);
|
||||||
|
|
||||||
await sleep(100);
|
await waitFor(() => {
|
||||||
|
const g2plot = document.querySelector('.g2plot') as HTMLDivElement;
|
||||||
const g2plot = document.querySelector('.g2plot') as HTMLDivElement;
|
expect(g2plot).toBeInTheDocument();
|
||||||
expect(g2plot).toBeInTheDocument();
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { render, screen, sleep, userEvent, within } from 'testUtils';
|
import { render, screen, userEvent, waitFor, within } from 'testUtils';
|
||||||
import App1 from '../demos/demo1';
|
import App1 from '../demos/demo1';
|
||||||
|
|
||||||
describe('RecordPicker', () => {
|
describe('RecordPicker', () => {
|
||||||
@ -10,17 +10,20 @@ describe('RecordPicker', () => {
|
|||||||
expect(selector).toBeInTheDocument();
|
expect(selector).toBeInTheDocument();
|
||||||
|
|
||||||
await userEvent.click(selector);
|
await userEvent.click(selector);
|
||||||
await sleep(100);
|
|
||||||
|
|
||||||
// 弹窗标题
|
await waitFor(() => {
|
||||||
expect(screen.getByText(/select record/i)).toBeInTheDocument();
|
// 弹窗标题
|
||||||
|
expect(screen.getByText(/select record/i)).toBeInTheDocument();
|
||||||
|
});
|
||||||
const checkboxes = document.querySelectorAll('.ant-checkbox');
|
const checkboxes = document.querySelectorAll('.ant-checkbox');
|
||||||
|
|
||||||
// 第 3 个选项的内容是: “软件开发”
|
// 第 3 个选项的内容是: “软件开发”
|
||||||
await userEvent.click(checkboxes[2]);
|
await userEvent.click(checkboxes[2]);
|
||||||
await userEvent.click(screen.getByText(/submit/i));
|
await userEvent.click(screen.getByText(/submit/i));
|
||||||
|
|
||||||
expect(within(selector).getByText(/软件开发/i)).toBeInTheDocument();
|
await waitFor(() => {
|
||||||
expect(screen.getByText(/软件开发/i, { selector: '.test-record-picker-read-pretty-item' })).toBeInTheDocument();
|
expect(within(selector).getByText(/软件开发/i)).toBeInTheDocument();
|
||||||
|
expect(screen.getByText(/软件开发/i, { selector: '.test-record-picker-read-pretty-item' })).toBeInTheDocument();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user