Skip to content

Commit ccd37bf

Browse files
committed
add tests for class with error prop
1 parent 2a3c409 commit ccd37bf

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

packages/browser/test/unit/eventbuilder.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,33 @@ describe('eventFromUnknownInput', () => {
134134
},
135135
});
136136
});
137+
138+
it('handles class with error prop', () => {
139+
const error = new Error('Some error');
140+
141+
class MyTestClass {
142+
prop1 = 'hello';
143+
prop2 = error;
144+
}
145+
146+
const event = eventFromUnknownInput(defaultStackParser, new MyTestClass());
147+
148+
expect(event.exception?.values?.[0]).toEqual(
149+
expect.objectContaining({
150+
mechanism: { handled: true, synthetic: true, type: 'generic' },
151+
type: 'Error',
152+
value: 'Some error',
153+
}),
154+
);
155+
expect(event.extra).toEqual({
156+
__serialized__: {
157+
prop1: 'hello',
158+
prop2: {
159+
message: 'Some error',
160+
name: 'Error',
161+
stack: expect.stringContaining('Error: Some error'),
162+
},
163+
},
164+
});
165+
});
137166
});

packages/utils/test/eventbuilder.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,35 @@ describe('eventFromUnknownInput', () => {
103103
});
104104
});
105105

106+
it('handles class with error prop', () => {
107+
const error = new Error('Some error');
108+
109+
class MyTestClass {
110+
prop1 = 'hello';
111+
prop2 = error;
112+
}
113+
114+
const event = eventFromUnknownInput(fakeClient, stackParser, new MyTestClass());
115+
116+
expect(event.exception?.values?.[0]).toEqual(
117+
expect.objectContaining({
118+
mechanism: { handled: true, synthetic: true, type: 'generic' },
119+
type: 'Error',
120+
value: 'Some error',
121+
}),
122+
);
123+
expect(event.extra).toEqual({
124+
__serialized__: {
125+
prop1: 'hello',
126+
prop2: {
127+
message: 'Some error',
128+
name: 'Error',
129+
stack: expect.stringContaining('Error: Some error'),
130+
},
131+
},
132+
});
133+
});
134+
106135
it.each([
107136
['empty object', {}, 'Object captured as exception with keys: [object has no keys]'],
108137
['pojo', { prop1: 'hello', prop2: 2 }, 'Object captured as exception with keys: prop1, prop2'],

0 commit comments

Comments
 (0)