Skip to content

Commit 5ebe9c3

Browse files
committed
test: added unit for unknown case
1 parent 183e337 commit 5ebe9c3

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

packages/browser-utils/test/metrics/inpt.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,35 @@ describe('_onInp', () => {
113113
transaction: undefined,
114114
});
115115
});
116+
117+
it('uses <unknown> as element name when entry.target is null and no cached name exists', () => {
118+
const startStandaloneWebVitalSpanSpy = vi.spyOn(utils, 'startStandaloneWebVitalSpan');
119+
120+
const metric = {
121+
value: 150,
122+
entries: [
123+
{
124+
name: 'click',
125+
duration: 150,
126+
interactionId: 999,
127+
target: null, // Element was removed from DOM
128+
startTime: 1234567,
129+
},
130+
],
131+
};
132+
// @ts-expect-error - incomplete metric object
133+
_onInp({ metric });
134+
135+
expect(startStandaloneWebVitalSpanSpy).toHaveBeenCalledTimes(1);
136+
expect(startStandaloneWebVitalSpanSpy).toHaveBeenCalledWith({
137+
attributes: {
138+
'sentry.exclusive_time': 150,
139+
'sentry.op': 'ui.interaction.click',
140+
'sentry.origin': 'auto.http.browser.inp',
141+
},
142+
name: '<unknown>', // Should fall back to <unknown> when element cannot be determined
143+
startTime: expect.any(Number),
144+
transaction: undefined,
145+
});
146+
});
116147
});

0 commit comments

Comments
 (0)