@@ -1018,4 +1018,51 @@ describe('Notification.Basic', () => {
10181018 'xxx' ,
10191019 ) ;
10201020 } ) ;
1021+
1022+ describe ( 'MAX_DURATION' , ( ) => {
1023+ it ( 'should not warn when duration is within limit' , ( ) => {
1024+ const { instance } = renderDemo ( ) ;
1025+ const errSpy = vi . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } ) ;
1026+
1027+ act ( ( ) => {
1028+ instance . open ( {
1029+ content : < p className = "test" > 1</ p > ,
1030+ duration : 0.1 ,
1031+ } ) ;
1032+ } ) ;
1033+
1034+ expect ( document . querySelector ( '.test' ) ) . toBeTruthy ( ) ;
1035+ expect ( errSpy ) . not . toHaveBeenCalled ( ) ;
1036+ } ) ;
1037+
1038+ it ( 'should warn and clamp when duration exceeds limit' , ( ) => {
1039+ const { instance } = renderDemo ( ) ;
1040+ const errSpy = vi . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } ) ;
1041+
1042+ const MAX_DURATION = 2147483647 / 1000 ;
1043+ const EXCEEDED_DURATION = ( 2147483647 + 1 ) / 1000 ;
1044+
1045+ act ( ( ) => {
1046+ instance . open ( {
1047+ content : < p className = "test" > 1</ p > ,
1048+ duration : EXCEEDED_DURATION ,
1049+ } ) ;
1050+ } ) ;
1051+
1052+ expect ( document . querySelector ( '.test' ) ) . toBeTruthy ( ) ;
1053+ expect ( errSpy ) . toHaveBeenCalledWith (
1054+ `Warning: \`duration\` exceeds the maximum supported value (${ MAX_DURATION } s) and has been clamped.` ,
1055+ ) ;
1056+
1057+ act ( ( ) => {
1058+ vi . advanceTimersByTime ( MAX_DURATION * 1000 - 1 ) ;
1059+ } ) ;
1060+ expect ( document . querySelector ( '.test' ) ) . toBeTruthy ( ) ;
1061+
1062+ act ( ( ) => {
1063+ vi . advanceTimersByTime ( 1 ) ;
1064+ } ) ;
1065+ expect ( document . querySelector ( '.test' ) ) . toBeFalsy ( ) ;
1066+ } ) ;
1067+ } ) ;
10211068} ) ;
0 commit comments