From 4a6983a2ee6c98635e127e0fa999905cf2deb34a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kry=C5=A1tof=20Wold=C5=99ich?= <31292499+krystofwoldrich@users.noreply.github.com> Date: Tue, 22 Nov 2022 13:36:02 +0100 Subject: [PATCH] chore(client): Add event normalization test (#2635) Co-authored-by: Krisztiaan Co-authored-by: Krisztiaan --- test/client.test.ts | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/test/client.test.ts b/test/client.test.ts index 10db54a942..0896d8e587 100644 --- a/test/client.test.ts +++ b/test/client.test.ts @@ -308,6 +308,37 @@ describe('Tests ReactNativeClient', () => { }); }); + describe('normalizes events', () => { + test('handles circular input', async () => { + const mockedSend = jest.fn, [Envelope]>(); + const mockedTransport = (): Transport => ({ + send: mockedSend, + flush: jest.fn().mockResolvedValue(true), + }); + const client = new ReactNativeClient( { + ...DEFAULT_OPTIONS, + dsn: EXAMPLE_DSN, + transport: mockedTransport, + }); + const circularEvent = { + extra: { + circular: {}, + }, + }; + circularEvent.extra.circular = circularEvent; + + client.captureEvent(circularEvent); + + expect(mockedSend).toBeCalled(); + const actualEvent: Event | undefined = mockedSend.mock.calls[0][firstArg][envelopeItems][0][envelopeItemPayload]; + expect(actualEvent?.extra).toEqual({ + circular: { + extra: '[Circular ~]', + }, + }); + }); + }); + describe('clientReports', () => { test('does not send client reports if disabled', () => { const mockTransportSend = jest.fn((_envelope: Envelope) => Promise.resolve());