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

test(Alert): add onClosed test #3756

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/alert/__tests__/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,24 @@ describe('Alert', () => {
expect(fn).toBeCalled();
expect(alert.classes()).toContain('t-alert--closing');
});
it(':onClosed', async () => {
const arr = [];
const fn1 = () => {
arr.push('fn1');
};
const fn2 = () => {
arr.push('fn2');
};
const wrapper = mount(() => (
<Alert close onClose={fn1()} onClosed={fn2()}>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

对应的是mock事件 不是执行事件
测试这种事件API有没有执行 用BeCalled expect 数组有没有和它执行没关系吧

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

主要是想测试他的先后执行顺序,根据数组数据的先后判断。

Copy link
Collaborator

@uyarn uyarn Dec 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by accident..
只是因为你在mount里写的顺序 fn() 是直接执行这个函数 不是等回调执行了来执行
刚好fn1被你写在fn2之前了 所以也就fn1先执行了 你试试把这两个换顺序是不是直接挂了..
<Alert close onClosed={fn2()} onClose={fn1()}>

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<Alert close onClose={fn1()} onClosed={fn2()}>
<Alert close onClose={fn1} onClosed={fn2}>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好,我试一下

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

主要是想测试他的先后执行顺序,根据数组数据的先后判断。

这个思路是可以的 就是具体内容得调整下

text
</Alert>
));
const close = wrapper.find('.t-alert__close');
await close.trigger('click');
await nextTick();
expect(arr[0]).toBe('fn1');
expect(arr[1]).toBe('fn2');
});
});
});
Loading