@@ -78,23 +78,23 @@ describe('pageLifecycle', () => {
7878 // Since no navigation library is mocked, callbacks should run immediately
7979 expect ( callback ) . toHaveBeenCalledTimes ( 1 ) ;
8080 // Should not add DOMContentLoaded listener since readyState is not 'loading'
81- expect ( addEventListenerSpy ) . not . toHaveBeenCalledWith ( 'DOMContentLoaded ' , expect . any ( Function ) ) ;
81+ expect ( addEventListenerSpy ) . not . toHaveBeenCalledWith ( 'readystatechange ' , expect . any ( Function ) ) ;
8282 } ) ;
8383
84- it ( 'should initialize page event listeners immediately when document.readyState is "interactive"' , ( ) => {
85- setReadyState ( 'interactive ' ) ;
84+ it ( 'should wait for readystatechange when document.readyState is "interactive"' , ( ) => {
85+ setReadyState ( 'loading ' ) ;
8686 const callback = jest . fn ( ) ;
8787 const { onPageLoaded } = importPageLifecycle ( ) ;
8888
8989 onPageLoaded ( callback ) ;
9090
91- // Since no navigation library is mocked, callbacks should run immediately
92- expect ( callback ) . toHaveBeenCalledTimes ( 1 ) ;
93- // Should not add DOMContentLoaded listener since readyState is not 'loading'
94- expect ( addEventListenerSpy ) . not . toHaveBeenCalledWith ( 'DOMContentLoaded ' , expect . any ( Function ) ) ;
91+ // Should not call callback immediately since readyState is 'loading'
92+ expect ( callback ) . not . toHaveBeenCalled ( ) ;
93+ // Verify that a DOMContentLoaded listener was added when readyState is 'loading'
94+ expect ( addEventListenerSpy ) . toHaveBeenCalledWith ( 'readystatechange ' , expect . any ( Function ) ) ;
9595 } ) ;
9696
97- it ( 'should wait for DOMContentLoaded when document.readyState is "loading"' , ( ) => {
97+ it ( 'should wait for readystatechange when document.readyState is "loading"' , ( ) => {
9898 setReadyState ( 'loading' ) ;
9999 const callback = jest . fn ( ) ;
100100 const { onPageLoaded } = importPageLifecycle ( ) ;
@@ -104,7 +104,7 @@ describe('pageLifecycle', () => {
104104 // Should not call callback immediately since readyState is 'loading'
105105 expect ( callback ) . not . toHaveBeenCalled ( ) ;
106106 // Verify that a DOMContentLoaded listener was added when readyState is 'loading'
107- expect ( addEventListenerSpy ) . toHaveBeenCalledWith ( 'DOMContentLoaded ' , expect . any ( Function ) ) ;
107+ expect ( addEventListenerSpy ) . toHaveBeenCalledWith ( 'readystatechange ' , expect . any ( Function ) ) ;
108108 } ) ;
109109
110110 describe ( 'with Turbo navigation library' , ( ) => {
0 commit comments