11import React from 'react' ;
22import { mount } from 'enzyme' ;
3+ import { act } from 'react-dom/test-utils' ;
34import Notification from '../src' ;
45
56require ( '../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