Skip to content

Commit

Permalink
perf: perf: message组件onDurationEnd事件测试用例优化
Browse files Browse the repository at this point in the history
  • Loading branch information
qunbotop committed Apr 8, 2022
1 parent 705660d commit 096158c
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions test/unit/message/index.test.js
Expand Up @@ -12,6 +12,7 @@ import Button from '@/src/button/index.ts';
import Loading from '@/src/loading';

// every component needs four parts: props/events/slots/functions.
jest.useFakeTimers();
describe('Message', () => {
// test props api
describe(':props', () => {
Expand Down Expand Up @@ -128,20 +129,17 @@ describe('Message', () => {

// test events
describe('@event', () => {
it('@duration-end', (done) => {
const wrapper = mount({
render() {
return <Message duration={3000}></Message>;
it('@duration-end', () => {
const onDurationEnd = jest.fn();
const wrapper = mount(Message, {
props: {
onDurationEnd,
duration: 3000,
},
});
const msg = wrapper.findComponent(Message);
expect(msg.emitted()['duration-end']).toBeFalsy();
const timer = setTimeout(() => {
const msg = wrapper.findComponent(Message);
expect(msg.emitted()['duration-end']).toBeTruthy();
done();
clearTimeout(timer);
}, 3100);
expect(onDurationEnd).not.toBeCalled();
jest.runAllTimers();
expect(onDurationEnd).toHaveBeenCalledTimes(1);
});
});

Expand Down

0 comments on commit 096158c

Please sign in to comment.