11import React from 'react' ;
2- import { mount , ReactWrapper } from 'enzyme' ;
2+ import type { ReactWrapper } from 'enzyme' ;
3+ import { mount } from 'enzyme' ;
34import Notification from '../src' ;
4- import { NotificationInstance } from '../src/Notification' ;
5+ import type { NotificationInstance } from '../src/Notification' ;
56
67require ( '../assets/index.less' ) ;
78
89async function timeout ( delay = 0 ) {
9- return new Promise ( resolve => {
10+ return new Promise ( ( resolve ) => {
1011 setTimeout ( resolve , delay ) ;
1112 } ) ;
1213}
@@ -24,7 +25,7 @@ describe('Notification.Hooks', () => {
2425 wrapper = mount ( < div > { node } </ div > ) ;
2526 } ,
2627 } as any ,
27- notification => {
28+ ( notification ) => {
2829 instance = notification ;
2930 } ,
3031 ) ;
@@ -64,4 +65,62 @@ describe('Notification.Hooks', () => {
6465
6566 instance . destroy ( ) ;
6667 } ) ;
68+
69+ it ( 'key replace' , async ( ) => {
70+ let instance : NotificationInstance ;
71+
72+ let wrapper : ReactWrapper ;
73+ Notification . newInstance (
74+ {
75+ TEST_RENDER : ( node : React . ReactElement ) => {
76+ wrapper = mount ( < div > { node } </ div > ) ;
77+ } ,
78+ } as any ,
79+ ( notification ) => {
80+ instance = notification ;
81+ } ,
82+ ) ;
83+
84+ await timeout ( 0 ) ;
85+
86+ const Demo = ( ) => {
87+ const [ notify , holder ] = instance . useNotification ( ) ;
88+ return (
89+ < >
90+ < button
91+ type = "button"
92+ onClick = { ( ) => {
93+ notify ( {
94+ key : 'little' ,
95+ duration : 1000 ,
96+ content : < div className = "context-content" > light</ div > ,
97+ } ) ;
98+
99+ setTimeout ( ( ) => {
100+ notify ( {
101+ key : 'little' ,
102+ duration : 1000 ,
103+ content : < div className = "context-content" > bamboo</ div > ,
104+ } ) ;
105+ } , 500 ) ;
106+ } }
107+ />
108+ { holder }
109+ </ >
110+ ) ;
111+ } ;
112+
113+ const demo = mount ( < Demo /> ) ;
114+ demo . find ( 'button' ) . simulate ( 'click' ) ;
115+
116+ await timeout ( 10 ) ;
117+ expect ( demo . find ( '.context-content' ) . text ( ) ) . toEqual ( 'light' ) ;
118+
119+ await timeout ( 600 ) ;
120+ expect ( demo . find ( '.context-content' ) . text ( ) ) . toEqual ( 'bamboo' ) ;
121+
122+ instance . destroy ( ) ;
123+
124+ wrapper . unmount ( ) ;
125+ } ) ;
67126} ) ;
0 commit comments