Skip to content

Commit 4a6983a

Browse files
chore(client): Add event normalization test (#2635)
Co-authored-by: Krisztiaan <k@perpixel.io> Co-authored-by: Krisztiaan <krisz011@gmail.com>
1 parent 4174a99 commit 4a6983a

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

test/client.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,37 @@ describe('Tests ReactNativeClient', () => {
308308
});
309309
});
310310

311+
describe('normalizes events', () => {
312+
test('handles circular input', async () => {
313+
const mockedSend = jest.fn<PromiseLike<void>, [Envelope]>();
314+
const mockedTransport = (): Transport => ({
315+
send: mockedSend,
316+
flush: jest.fn().mockResolvedValue(true),
317+
});
318+
const client = new ReactNativeClient(<ReactNativeClientOptions> {
319+
...DEFAULT_OPTIONS,
320+
dsn: EXAMPLE_DSN,
321+
transport: mockedTransport,
322+
});
323+
const circularEvent = {
324+
extra: {
325+
circular: {},
326+
},
327+
};
328+
circularEvent.extra.circular = circularEvent;
329+
330+
client.captureEvent(circularEvent);
331+
332+
expect(mockedSend).toBeCalled();
333+
const actualEvent: Event | undefined = <Event>mockedSend.mock.calls[0][firstArg][envelopeItems][0][envelopeItemPayload];
334+
expect(actualEvent?.extra).toEqual({
335+
circular: {
336+
extra: '[Circular ~]',
337+
},
338+
});
339+
});
340+
});
341+
311342
describe('clientReports', () => {
312343
test('does not send client reports if disabled', () => {
313344
const mockTransportSend = jest.fn((_envelope: Envelope) => Promise.resolve());

0 commit comments

Comments
 (0)