Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix ci #39811

Merged
merged 4 commits into from Dec 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions components/form/__tests__/index.test.tsx
Expand Up @@ -639,7 +639,7 @@ describe('Form', () => {
value = '',
id,
}) => {
shouldRender();
shouldRender(value);
return <input id={id} value={value} />;
};

Expand Down Expand Up @@ -667,8 +667,10 @@ describe('Form', () => {

expect(formRef.current!.getFieldsValue()).toEqual({ light: 'bamboo' });

expect(container.querySelector<HTMLInputElement>('#changed')!.value).toEqual('bamboo');
await waitFakeTimer();

expect(shouldNotRender).toHaveBeenCalledTimes(1);
expect(shouldRender).toHaveBeenLastCalledWith('bamboo');
expect(shouldRender).toHaveBeenCalledTimes(2);
});

Expand Down
28 changes: 12 additions & 16 deletions components/modal/__tests__/hook.test.tsx
Expand Up @@ -2,7 +2,7 @@ import CSSMotion from 'rc-motion';
import { genCSSMotion } from 'rc-motion/lib/CSSMotion';
import KeyCode from 'rc-util/lib/KeyCode';
import React from 'react';
import TestUtils, { act } from 'react-dom/test-utils';
import { act } from 'react-dom/test-utils';

import Modal from '..';
import { fireEvent, render, waitFakeTimer } from '../../../tests/utils';
Expand Down Expand Up @@ -199,10 +199,6 @@ describe('Modal.hook', () => {
it('the callback close should be a method when onCancel has a close parameter', async () => {
jest.useFakeTimers();

const clear = async function clear() {
await waitFakeTimer();
};

const mockFn = jest.fn();

const Demo = () => {
Expand All @@ -229,57 +225,57 @@ describe('Modal.hook', () => {

const { container } = render(<Demo />);

await clear();
await waitFakeTimer();

expect(document.body.querySelectorAll('.ant-modal-confirm-confirm')).toHaveLength(0);
// First open
fireEvent.click(container.querySelectorAll('.open-hook-modal-btn')[0]);
await clear();
await waitFakeTimer();

expect(document.body.querySelectorAll('.ant-modal-confirm-confirm')).toHaveLength(1);
// Click mask to close
fireEvent.click(document.body.querySelectorAll('.ant-modal-wrap')[0]);

await clear();
await waitFakeTimer();

expect(document.body.querySelectorAll('.ant-modal-confirm-confirm')).toHaveLength(0);
// Second open
fireEvent.click(container.querySelectorAll('.open-hook-modal-btn')[0]);

await clear();
await waitFakeTimer();

expect(document.body.querySelectorAll('.ant-modal-confirm-confirm')).toHaveLength(1);
// Press ESC to turn off
TestUtils.Simulate.keyDown(document.body.querySelectorAll('.ant-modal')[0], {
fireEvent.keyDown(document.body.querySelectorAll('.ant-modal')[0], {
keyCode: KeyCode.ESC,
});

await clear();
await waitFakeTimer();

expect(document.body.querySelectorAll('.ant-modal-confirm-confirm')).toHaveLength(0);
// Third open
fireEvent.click(container.querySelectorAll('.open-hook-modal-btn')[0]);

await clear();
await waitFakeTimer();

expect(document.body.querySelectorAll('.ant-modal-confirm-confirm')).toHaveLength(1);
// Click the close icon to close
fireEvent.click(document.body.querySelectorAll('.ant-modal-close')[0]);

await clear();
await waitFakeTimer();

expect(document.body.querySelectorAll('.ant-modal-confirm-confirm')).toHaveLength(0);
// Last open
fireEvent.click(container.querySelectorAll('.open-hook-modal-btn')[0]);

await clear();
await waitFakeTimer();

expect(document.body.querySelectorAll('.ant-modal-confirm-confirm')).toHaveLength(1);

// Click the Cancel button to close (invalid)
fireEvent.click(document.body.querySelectorAll('.ant-modal-confirm-btns > .ant-btn')[0]);

await clear();
await waitFakeTimer();

expect(document.body.querySelectorAll('.ant-modal-confirm-confirm')).toHaveLength(1);

Expand All @@ -288,7 +284,7 @@ describe('Modal.hook', () => {
// Click the Cancel button to close (valid)
fireEvent.click(document.body.querySelectorAll('.ant-modal-confirm-btns > .ant-btn')[0]);

await clear();
await waitFakeTimer();

expect(document.body.querySelectorAll('.ant-modal-confirm-confirm')).toHaveLength(0);

Expand Down