Skip to content

Commit cb5355c

Browse files
committed
test: Update test case
1 parent fdf82a2 commit cb5355c

2 files changed

Lines changed: 39 additions & 25 deletions

File tree

examples/simple.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,18 @@ import Notification from '../src';
44
import '../assets/index.less';
55

66
let notification = null;
7-
Notification.newInstance({}, n => {
8-
notification = n;
9-
});
7+
Notification.newInstance(
8+
{
9+
maxCount: 5,
10+
},
11+
n => {
12+
notification = n;
13+
},
14+
);
1015

1116
function simpleFn() {
1217
notification.notice({
13-
content: <span>simple show</span>,
18+
content: <span>simple show {Date.now()}</span>,
1419
onClose() {
1520
console.log('simple close');
1621
},

tests/index.test.js

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22
import { mount } from 'enzyme';
3+
import { act } from 'react-dom/test-utils';
34
import Notification from '../src';
45

56
require('../assets/index.less');
@@ -300,9 +301,12 @@ describe('Notification.Basic', () => {
300301
mount(<Test />, container);
301302
});
302303

303-
it('drop first notice when items limit exceeds', done => {
304+
it('drop first notice when items limit exceeds', () => {
305+
jest.useFakeTimers();
306+
304307
let wrapper;
305308

309+
let notificationInstance;
306310
Notification.newInstance(
307311
{
308312
maxCount: 1,
@@ -311,28 +315,33 @@ describe('Notification.Basic', () => {
311315
},
312316
},
313317
notification => {
314-
const value = 'updated last';
315-
notification.notice({
316-
content: <span className="test-maxcount">simple show</span>,
317-
duration: 3,
318-
});
319-
notification.notice({
320-
content: <span className="test-maxcount">simple show</span>,
321-
duration: 3,
322-
});
323-
notification.notice({
324-
content: <span className="test-maxcount">{value}</span>,
325-
duration: 3,
326-
});
327-
328-
setTimeout(() => {
329-
wrapper.update();
330-
expect(wrapper.find('.test-maxcount')).toHaveLength(1);
331-
expect(wrapper.find('.test-maxcount').text()).toEqual(value);
332-
done();
333-
}, 10);
318+
notificationInstance = notification;
334319
},
335320
);
321+
322+
const value = 'updated last';
323+
notificationInstance.notice({
324+
content: <span className="test-maxcount">simple show</span>,
325+
duration: 0,
326+
});
327+
notificationInstance.notice({
328+
content: <span className="test-maxcount">simple show</span>,
329+
duration: 0,
330+
});
331+
notificationInstance.notice({
332+
content: <span className="test-maxcount">{value}</span>,
333+
duration: 0,
334+
});
335+
336+
act(() => {
337+
jest.runAllTimers();
338+
wrapper.update();
339+
});
340+
341+
expect(wrapper.find('.test-maxcount')).toHaveLength(1);
342+
expect(wrapper.find('.test-maxcount').text()).toEqual(value);
343+
344+
jest.useRealTimers();
336345
});
337346

338347
it('onClick trigger', done => {

0 commit comments

Comments
 (0)