11import React from 'react' ;
2- import type { ReactWrapper } from 'enzyme' ;
3- import { mount } from 'enzyme' ;
2+ import { render , fireEvent } from '@testing-library/react' ;
43import Notification from '../src' ;
54import type { NotificationInstance } from '../src/Notification' ;
65
@@ -18,11 +17,11 @@ describe('Notification.Hooks', () => {
1817
1918 const Context = React . createContext ( { name : 'light' } ) ;
2019
21- let wrapper : ReactWrapper ;
20+ let container : HTMLElement ;
2221 Notification . newInstance (
2322 {
2423 TEST_RENDER : ( node : React . ReactElement ) => {
25- wrapper = mount ( < div > { node } </ div > ) ;
24+ ( { container } = render ( < div > { node } </ div > ) ) ;
2625 } ,
2726 } as any ,
2827 ( notification ) => {
@@ -54,26 +53,27 @@ describe('Notification.Hooks', () => {
5453 ) ;
5554 } ;
5655
57- const demo = mount ( < Demo /> ) ;
58- demo . find ( 'button' ) . simulate ( 'click' ) ;
56+ const { container : demoContainer } = render ( < Demo /> ) ;
57+ fireEvent . click ( demoContainer . querySelector ( 'button' ) ) ;
5958
6059 await timeout ( 10 ) ;
61- expect ( demo . find ( '.context-content' ) . text ( ) ) . toEqual ( 'bamboo' ) ;
60+ expect ( container . querySelector ( '.context-content' ) . textContent ) . toEqual ( 'bamboo' ) ;
6261
6362 await timeout ( 1000 ) ;
64- expect ( wrapper . find ( 'Notification' ) . state ( ) . notices ) . toHaveLength ( 0 ) ;
63+ expect ( container . querySelectorAll ( '.rc-notification-notice' ) ) . toHaveLength ( 0 ) ;
6564
6665 instance . destroy ( ) ;
6766 } ) ;
6867
6968 it ( 'key replace' , async ( ) => {
7069 let instance : NotificationInstance ;
7170
72- let wrapper : ReactWrapper ;
71+ let container : HTMLElement ;
72+ let unmount : ( ) => void ;
7373 Notification . newInstance (
7474 {
7575 TEST_RENDER : ( node : React . ReactElement ) => {
76- wrapper = mount ( < div > { node } </ div > ) ;
76+ ( { container , unmount } = render ( < div > { node } </ div > ) ) ;
7777 } ,
7878 } as any ,
7979 ( notification ) => {
@@ -110,17 +110,17 @@ describe('Notification.Hooks', () => {
110110 ) ;
111111 } ;
112112
113- const demo = mount ( < Demo /> ) ;
114- demo . find ( 'button' ) . simulate ( 'click' ) ;
113+ const { container : demoContainer } = render ( < Demo /> ) ;
114+ fireEvent . click ( demoContainer . querySelector ( 'button' ) ) ;
115115
116116 await timeout ( 10 ) ;
117- expect ( demo . find ( '.context-content' ) . text ( ) ) . toEqual ( 'light' ) ;
117+ expect ( container . querySelector ( '.context-content' ) . textContent ) . toEqual ( 'light' ) ;
118118
119119 await timeout ( 600 ) ;
120- expect ( demo . find ( '.context-content' ) . text ( ) ) . toEqual ( 'bamboo' ) ;
120+ expect ( container . querySelector ( '.context-content' ) . textContent ) . toEqual ( 'bamboo' ) ;
121121
122122 instance . destroy ( ) ;
123123
124- wrapper . unmount ( ) ;
124+ unmount ( ) ;
125125 } ) ;
126126} ) ;
0 commit comments