@@ -23,50 +23,86 @@ describe('_trackINP', () => {
23
23
} ) ;
24
24
25
25
describe ( '_onInp' , ( ) => {
26
- const startStandaloneWebVitalSpan = vi . spyOn ( utils , 'startStandaloneWebVitalSpan' ) ;
27
-
28
- beforeEach ( ( ) => {
29
- vi . clearAllMocks ( ) ;
30
- } ) ;
31
-
32
26
it ( 'early-returns if the INP metric entry has no value' , ( ) => {
27
+ const startStandaloneWebVitalSpanSpy = vi . spyOn ( utils , 'startStandaloneWebVitalSpan' ) ;
28
+
33
29
const metric = {
34
30
value : undefined ,
35
31
entries : [ ] ,
36
32
} ;
37
33
// @ts -expect-error - incomplete metric object
38
34
_onInp ( { metric } ) ;
39
- expect ( startStandaloneWebVitalSpan ) . not . toHaveBeenCalled ( ) ;
35
+
36
+ expect ( startStandaloneWebVitalSpanSpy ) . not . toHaveBeenCalled ( ) ;
40
37
} ) ;
41
38
42
39
it ( 'early-returns if the INP metric value is greater than 60 seconds' , ( ) => {
40
+ const startStandaloneWebVitalSpanSpy = vi . spyOn ( utils , 'startStandaloneWebVitalSpan' ) ;
41
+
43
42
const metric = {
44
43
value : 60_001 ,
45
- entries : [ { name : 'click' , duration : 60_001 , interactionId : 1 } ] ,
44
+ entries : [
45
+ { name : 'click' , duration : 60_001 , interactionId : 1 } ,
46
+ { name : 'click' , duration : 60_000 , interactionId : 2 } ,
47
+ ] ,
46
48
} ;
47
49
// @ts -expect-error - incomplete metric object
48
50
_onInp ( { metric } ) ;
49
- expect ( startStandaloneWebVitalSpan ) . not . toHaveBeenCalled ( ) ;
51
+
52
+ expect ( startStandaloneWebVitalSpanSpy ) . not . toHaveBeenCalled ( ) ;
50
53
} ) ;
51
54
52
55
it ( 'early-returns if the inp metric has an unknown interaction type' , ( ) => {
56
+ const startStandaloneWebVitalSpanSpy = vi . spyOn ( utils , 'startStandaloneWebVitalSpan' ) ;
57
+
53
58
const metric = {
54
59
value : 10 ,
55
60
entries : [ { name : 'unknown' , duration : 10 , interactionId : 1 } ] ,
56
61
} ;
57
62
// @ts -expect-error - incomplete metric object
58
63
_onInp ( { metric } ) ;
59
- expect ( startStandaloneWebVitalSpan ) . not . toHaveBeenCalled ( ) ;
64
+
65
+ expect ( startStandaloneWebVitalSpanSpy ) . not . toHaveBeenCalled ( ) ;
60
66
} ) ;
61
67
62
68
it ( 'starts a span for a valid INP metric entry' , ( ) => {
69
+ const startStandaloneWebVitalSpanSpy = vi . spyOn ( utils , 'startStandaloneWebVitalSpan' ) ;
70
+
63
71
const metric = {
64
72
value : 10 ,
65
73
entries : [ { name : 'click' , duration : 10 , interactionId : 1 } ] ,
66
74
} ;
67
75
// @ts -expect-error - incomplete metric object
68
76
_onInp ( { metric } ) ;
69
- expect ( startStandaloneWebVitalSpan ) . toHaveBeenCalledWith ( {
77
+
78
+ expect ( startStandaloneWebVitalSpanSpy ) . toHaveBeenCalledTimes ( 1 ) ;
79
+ expect ( startStandaloneWebVitalSpanSpy ) . toHaveBeenCalledWith ( {
80
+ attributes : {
81
+ 'sentry.exclusive_time' : 10 ,
82
+ 'sentry.op' : 'ui.interaction.click' ,
83
+ 'sentry.origin' : 'auto.http.browser.inp' ,
84
+ } ,
85
+ name : '<unknown>' ,
86
+ startTime : NaN ,
87
+ transaction : undefined ,
88
+ } ) ;
89
+ } ) ;
90
+
91
+ it ( 'takes the correct entry based on the metric value' , ( ) => {
92
+ const startStandaloneWebVitalSpanSpy = vi . spyOn ( utils , 'startStandaloneWebVitalSpan' ) ;
93
+
94
+ const metric = {
95
+ value : 10 ,
96
+ entries : [
97
+ { name : 'click' , duration : 10 , interactionId : 1 } ,
98
+ { name : 'click' , duration : 9 , interactionId : 2 } ,
99
+ ] ,
100
+ } ;
101
+ // @ts -expect-error - incomplete metric object
102
+ _onInp ( { metric } ) ;
103
+
104
+ expect ( startStandaloneWebVitalSpanSpy ) . toHaveBeenCalledTimes ( 1 ) ;
105
+ expect ( startStandaloneWebVitalSpanSpy ) . toHaveBeenCalledWith ( {
70
106
attributes : {
71
107
'sentry.exclusive_time' : 10 ,
72
108
'sentry.op' : 'ui.interaction.click' ,
0 commit comments