Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: normalize test #805

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 23 additions & 19 deletions test/utils/normalize.test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
import { getClient } from '@sentry/core';
import * as SentryCore from '@sentry/core';

jest.mock('@sentry/core', () => ({
getClient: jest.fn(),
}));
import { enableSyncToNative } from '../../src/scopeSync';
import { convertToNormalizedObject } from '../../src/utils/normalize';
import { getDefaultTestClientOptions, TestClient } from '../mocks/client';

describe('normalize', () => {
describe('convertToNormalizedObject', () => {
beforeEach(() => {
(getClient as jest.Mock).mockReturnValue({
getOptions: jest.fn().mockReturnValue({
normalizeDepth: undefined,
normalizeMaxBreadth: undefined,
}),
});
});
afterEach(() => {
jest.resetAllMocks();
});

describe('convertToNormalizedObject', () => {
test('output equals input for normalized objects', () => {
const actualResult = convertToNormalizedObject({ foo: 'bar' });
expect(actualResult).toEqual({ foo: 'bar' });
Expand All @@ -36,13 +30,23 @@ describe('normalize', () => {
expect(actualResult).toEqual({ value: null });
});

test('converts array to an object', () => {
const actualResult = convertToNormalizedObject([]);
expect(actualResult).toEqual([]);
});

test('converts custom class to an object', () => {
class TestClass {
test: string = 'foo';
}
const actualResult = convertToNormalizedObject(new TestClass());
expect(actualResult).toEqual({ test: 'foo' });
});

test('respect normalizeDepth and normalizeMaxBreadth when set', () => {
(getClient as jest.Mock).mockReturnValue({
getOptions: jest.fn().mockReturnValue({
normalizeDepth: 2,
normalizeMaxBreadth: 3,
})
});
SentryCore.setCurrentClient(new TestClient(getDefaultTestClientOptions({ normalizeDepth: 2, normalizeMaxBreadth: 3})));
enableSyncToNative(SentryCore.getIsolationScope());

const obj = {
key1: '1',
keyparent: {
Expand Down
Loading