11import React from 'react' ;
2- import { mount } from 'enzyme' ;
2+ import { mount , ReactWrapper } from 'enzyme' ;
33import Notification from '../src' ;
4+ import { NotificationInstance } from '../src/Notification' ;
45
56require ( '../assets/index.less' ) ;
67
@@ -12,13 +13,21 @@ async function timeout(delay = 0) {
1213
1314describe ( 'Notification.Hooks' , ( ) => {
1415 it ( 'works' , async ( ) => {
15- let instance ;
16+ let instance : NotificationInstance ;
1617
1718 const Context = React . createContext ( { name : 'light' } ) ;
1819
19- Notification . newInstance ( { } , notification => {
20- instance = notification ;
21- } ) ;
20+ let wrapper : ReactWrapper ;
21+ Notification . newInstance (
22+ {
23+ TEST_RENDER : ( node : React . ReactElement ) => {
24+ wrapper = mount ( < div > { node } </ div > ) ;
25+ } ,
26+ } as any ,
27+ notification => {
28+ instance = notification ;
29+ } ,
30+ ) ;
2231
2332 await timeout ( 0 ) ;
2433
@@ -30,6 +39,7 @@ describe('Notification.Hooks', () => {
3039 type = "button"
3140 onClick = { ( ) => {
3241 notify ( {
42+ duration : 0.1 ,
3343 content : (
3444 < Context . Consumer >
3545 { ( { name } ) => < div className = "context-content" > { name } </ div > }
@@ -50,6 +60,8 @@ describe('Notification.Hooks', () => {
5060 expect ( demo . find ( '.context-content' ) . text ( ) ) . toEqual ( 'bamboo' ) ;
5161
5262 await timeout ( 1000 ) ;
63+ expect ( wrapper . find ( 'Notification' ) . state ( ) . notices ) . toHaveLength ( 0 ) ;
64+
5365 instance . destroy ( ) ;
5466 } ) ;
5567} ) ;
0 commit comments