Skip to content

Commit d3c6abd

Browse files
fix normalize test (#805)
1 parent fd5c860 commit d3c6abd

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

test/utils/normalize.test.ts

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
1-
import { getClient } from '@sentry/core';
1+
import * as SentryCore from '@sentry/core';
22

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

87
describe('normalize', () => {
9-
describe('convertToNormalizedObject', () => {
10-
beforeEach(() => {
11-
(getClient as jest.Mock).mockReturnValue({
12-
getOptions: jest.fn().mockReturnValue({
13-
normalizeDepth: undefined,
14-
normalizeMaxBreadth: undefined,
15-
}),
16-
});
17-
});
8+
afterEach(() => {
9+
jest.resetAllMocks();
10+
});
1811

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

33+
test('converts array to an object', () => {
34+
const actualResult = convertToNormalizedObject([]);
35+
expect(actualResult).toEqual([]);
36+
});
37+
38+
test('converts custom class to an object', () => {
39+
class TestClass {
40+
test: string = 'foo';
41+
}
42+
const actualResult = convertToNormalizedObject(new TestClass());
43+
expect(actualResult).toEqual({ test: 'foo' });
44+
});
45+
3946
test('respect normalizeDepth and normalizeMaxBreadth when set', () => {
40-
(getClient as jest.Mock).mockReturnValue({
41-
getOptions: jest.fn().mockReturnValue({
42-
normalizeDepth: 2,
43-
normalizeMaxBreadth: 3,
44-
})
45-
});
47+
SentryCore.setCurrentClient(new TestClient(getDefaultTestClientOptions({ normalizeDepth: 2, normalizeMaxBreadth: 3})));
48+
enableSyncToNative(SentryCore.getIsolationScope());
49+
4650
const obj = {
4751
key1: '1',
4852
keyparent: {

0 commit comments

Comments
 (0)