@@ -75,26 +75,25 @@ describe('console-accessible values on the window object', function () {
7575 } ) ;
7676
7777 describe ( 'totalMarkerDuration' , function ( ) {
78- let target ;
79- let consoleLogSpy ;
78+ function setup ( ) {
79+ jest . spyOn ( console , 'log' ) . mockImplementation ( ( ) => { } ) ;
8080
81- beforeEach ( function ( ) {
8281 const store = storeWithSimpleProfile ( ) ;
83- target = { } ;
82+ const target = { } ;
8483 addDataToWindowObject ( store . getState , store . dispatch , target ) ;
85- consoleLogSpy = jest . spyOn ( console , 'log' ) . mockImplementation ( ( ) => { } ) ;
86- } ) ;
8784
88- afterEach ( function ( ) {
89- consoleLogSpy . mockRestore ( ) ;
90- } ) ;
85+ return target ;
86+ }
87+ beforeEach ( function ( ) { } ) ;
9188
9289 it ( 'returns 0 for empty array' , function ( ) {
90+ const target = setup ( ) ;
9391 const result = target . totalMarkerDuration ( [ ] ) ;
9492 expect ( result ) . toBe ( 0 ) ;
9593 } ) ;
9694
9795 it ( 'returns 0 and logs error for non-array input' , function ( ) {
96+ const target = setup ( ) ;
9897 const consoleErrorSpy = jest
9998 . spyOn ( console , 'error' )
10099 . mockImplementation ( ( ) => { } ) ;
@@ -107,6 +106,7 @@ describe('console-accessible values on the window object', function () {
107106 } ) ;
108107
109108 it ( 'calculates duration for interval markers' , function ( ) {
109+ const target = setup ( ) ;
110110 const markers = [
111111 {
112112 start : 100 ,
@@ -125,9 +125,13 @@ describe('console-accessible values on the window object', function () {
125125 ] ;
126126 const result = target . totalMarkerDuration ( markers ) ;
127127 expect ( result ) . toBe ( 200 ) ; // (200-100) + (250-150) = 100 + 100 = 200
128+
129+ // Make sure that we print a formatted log for the duration.
130+ expect ( console . log ) . toHaveBeenCalledWith ( 'Total marker duration: 200ms' ) ;
128131 } ) ;
129132
130133 it ( 'skips instant markers with null end times' , function ( ) {
134+ const target = setup ( ) ;
131135 const markers = [
132136 {
133137 start : 100 ,
@@ -159,6 +163,7 @@ describe('console-accessible values on the window object', function () {
159163 } ) ;
160164
161165 it ( 'handles mixed valid and invalid markers' , function ( ) {
166+ const target = setup ( ) ;
162167 const markers = [
163168 {
164169 start : 100 ,
@@ -189,22 +194,5 @@ describe('console-accessible values on the window object', function () {
189194 const result = target . totalMarkerDuration ( markers ) ;
190195 expect ( result ) . toBe ( 200 ) ; // (200-100) + (500-400) = 100 + 100 = 200
191196 } ) ;
192-
193- it ( 'logs formatted duration to console' , function ( ) {
194- const markers = [
195- {
196- start : 100 ,
197- end : 350 ,
198- name : 'marker' ,
199- category : 0 ,
200- threadId : null ,
201- data : null ,
202- } ,
203- ] ;
204- target . totalMarkerDuration ( markers ) ;
205- expect ( consoleLogSpy ) . toHaveBeenCalledWith (
206- 'Total marker duration: 250ms'
207- ) ;
208- } ) ;
209197 } ) ;
210198} ) ;
0 commit comments