@@ -778,6 +778,104 @@ describe('Notification.Basic', () => {
778778 unmount ( ) ;
779779 } ) ;
780780
781+ describe ( 'onClose and closable.onClose' , ( ) => {
782+ it ( 'onClose' , ( ) => {
783+ const onClose = vi . fn ( ) ;
784+ const Demo = ( ) => {
785+ const [ api , holder ] = useNotification ( ) ;
786+ return (
787+ < >
788+ < button
789+ type = "button"
790+ onClick = { ( ) => {
791+ api . open ( {
792+ key : 'little' ,
793+ duration : 1 ,
794+ content : < div className = "context-content" > light</ div > ,
795+ closable : { onClose } ,
796+ } ) ;
797+ } }
798+ />
799+ { holder }
800+ </ >
801+ ) ;
802+ } ;
803+
804+ const { container : demoContainer , unmount } = render ( < Demo /> ) ;
805+ fireEvent . click ( demoContainer . querySelector ( 'button' ) ) ;
806+ act ( ( ) => {
807+ vi . runAllTimers ( ) ;
808+ } ) ;
809+ expect ( onClose ) . toHaveBeenCalled ( ) ;
810+
811+ unmount ( ) ;
812+ } ) ;
813+ it ( 'Both closableOnllose and onClose are called' , ( ) => {
814+ const onClose = vi . fn ( ) ;
815+ const closableOnClose = vi . fn ( ) ;
816+ const Demo = ( ) => {
817+ const [ api , holder ] = useNotification ( ) ;
818+ return (
819+ < >
820+ < button
821+ type = "button"
822+ onClick = { ( ) => {
823+ api . open ( {
824+ key : 'little' ,
825+ duration : 1 ,
826+ content : < div className = "context-content" > light</ div > ,
827+ onClose,
828+ closable : { onClose : closableOnClose } ,
829+ } ) ;
830+ } }
831+ />
832+ { holder }
833+ </ >
834+ ) ;
835+ } ;
836+
837+ const { container : demoContainer , unmount } = render ( < Demo /> ) ;
838+ fireEvent . click ( demoContainer . querySelector ( 'button' ) ) ;
839+ act ( ( ) => {
840+ vi . runAllTimers ( ) ;
841+ } ) ;
842+ expect ( closableOnClose ) . toHaveBeenCalled ( ) ;
843+ expect ( onClose ) . toHaveBeenCalled ( ) ;
844+
845+ unmount ( ) ;
846+ } ) ;
847+ it ( 'closable.onClose (config)' , ( ) => {
848+ const onClose = vi . fn ( ) ;
849+ const Demo = ( ) => {
850+ const [ api , holder ] = useNotification ( { closable : { onClose } } ) ;
851+ return (
852+ < >
853+ < button
854+ type = "button"
855+ onClick = { ( ) => {
856+ api . open ( {
857+ key : 'little' ,
858+ duration : 1 ,
859+ content : < div className = "context-content" > light</ div > ,
860+ } ) ;
861+ } }
862+ />
863+ { holder }
864+ </ >
865+ ) ;
866+ } ;
867+
868+ const { container : demoContainer , unmount } = render ( < Demo /> ) ;
869+ fireEvent . click ( demoContainer . querySelector ( 'button' ) ) ;
870+ act ( ( ) => {
871+ vi . runAllTimers ( ) ;
872+ } ) ;
873+ expect ( onClose ) . toHaveBeenCalled ( ) ;
874+
875+ unmount ( ) ;
876+ } ) ;
877+ } ) ;
878+
781879 it ( 'closes via keyboard Enter key' , ( ) => {
782880 const { instance } = renderDemo ( ) ;
783881 let closeCount = 0 ;
0 commit comments