Skip to content

Commit

Permalink
test: move notice-bar and collapse to rtl
Browse files Browse the repository at this point in the history
  • Loading branch information
shenhaidada committed Feb 27, 2024
1 parent 1fda677 commit d2a7532
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
17 changes: 5 additions & 12 deletions packages/arcodesign/components/collapse/__test__/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { render } from '@testing-library/react';
import { act } from 'react-dom/test-utils';
import { defaultContext } from '../../context-provider';
import userEvent from '@testing-library/user-event';
import { pureDelay } from '../../../tests/helpers/utils';

const prefix = `${defaultContext.prefixCls}-collapse`;
const headerPrefix = `.${prefix}-header`;
Expand Down Expand Up @@ -51,9 +52,7 @@ describe('Collapse', () => {
const header = container.querySelectorAll(headerPrefix)[0];
userEvent.click(header);
// 有动画,在这停顿!
act(() => {
jest.advanceTimersByTime(1000);
});
pureDelay(1000);
const content = container.querySelectorAll(contentPrefix)[0];
const contentStyle = getComputedStyle(content);
expect(contentStyle.getPropertyValue('height')).toBe('auto');
Expand Down Expand Up @@ -106,9 +105,7 @@ describe('Collapse', () => {
}
/>,
);
act(() => {
jest.advanceTimersByTime(1000);
});
pureDelay(1000);
const header = container.querySelectorAll(headerPrefix)[0];
userEvent.click(header);
const contentContainer = container.querySelectorAll(containerPrefix)[0];
Expand All @@ -125,9 +122,7 @@ describe('Collapse', () => {
expect(contentStyle.getPropertyValue('height')).toBe('0px');
const header = container.querySelectorAll(headerPrefix)[0];
userEvent.click(header);
act(() => {
jest.advanceTimersByTime(1000);
});
pureDelay(1000);
expect(contentStyle.getPropertyValue('height')).toBe('0px');
});

Expand Down Expand Up @@ -160,9 +155,7 @@ describe('Collapse', () => {

const header = container.querySelectorAll(headerPrefix)[2];
userEvent.click(header);
act(() => {
jest.advanceTimersByTime(1000);
});
pureDelay(1000);

expect(getContentHeightByIndex(0)).toBe('0px');
expect(getContentHeightByIndex(1)).toBe('auto');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { defaultContext } from '../../context-provider';
import { defineHtmlRefProperties } from '../../../tests/helpers/mockElement';
import { render } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { pureDelay } from '../../../tests/helpers/utils';

const { prefixCls } = defaultContext;
const prefix = `${prefixCls}-notice-bar`;
Expand Down Expand Up @@ -98,9 +99,7 @@ describe('NoticeBar actions', () => {
const noticeBar = container.querySelectorAll(`.${prefix}`)[0];

userEvent.click(noticeBar);
act(() => {
jest.advanceTimersByTime(2000);
});
pureDelay(2000);
const content = container.querySelectorAll(`.${prefix}-content-inner`)[0];
expect(content.textContent).toBe(longText);
});
Expand Down

0 comments on commit d2a7532

Please sign in to comment.