Skip to content

Commit ddc74b7

Browse files
Turbo87kamilogorek
authored andcommitted
test: [browser/LinkedErrors] Improve test code to be more realistic (#1694)
* browser/LinkedErrors/test: Use `BrowserBackend` to generate `event` The current implementation was missing the original exception in the `result.exception.values` array, which lead to the tests asserting on unrealistic results. This commit changes the test code to use the `BrowserBackend` class to generate the `event` from the actual exception. * browser/LinkedErrors/test: Rearrange errors to visualize creation order `one` depends on `two` depends on `three`
1 parent f6bf0fd commit ddc74b7

File tree

1 file changed

+32
-32
lines changed

1 file changed

+32
-32
lines changed

packages/browser/test/integrations/linkederrors.test.ts

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { expect } from 'chai';
22
import { stub } from 'sinon';
3+
import { BrowserBackend } from '../../src/backend';
34
import { LinkedErrors } from '../../src/integrations/linkederrors';
45

56
let linkedErrors: LinkedErrors;
@@ -52,67 +53,66 @@ describe('LinkedErrors', () => {
5253
expect(spy.calledOnce).equal(true);
5354
});
5455

55-
it('should recursively walk error to find linked exceptions and assign them to the event', () => {
56-
const event = {
57-
exception: {
58-
values: [],
59-
},
60-
message: 'foo',
61-
};
56+
it('should recursively walk error to find linked exceptions and assign them to the event', async () => {
57+
const three: ExtendedError = new SyntaxError('three');
6258

63-
const one: ExtendedError = new Error('one');
6459
const two: ExtendedError = new TypeError('two');
65-
const three: ExtendedError = new SyntaxError('three');
60+
two.cause = three;
6661

67-
const originalException = one;
62+
const one: ExtendedError = new Error('one');
6863
one.cause = two;
69-
two.cause = three;
7064

65+
const originalException = one;
66+
const backend = new BrowserBackend({});
67+
const event = await backend.eventFromException(originalException);
7168
const result = linkedErrors.handler(event, {
7269
originalException,
7370
});
7471

7572
// It shouldn't include root exception, as it's already processed in the event by the main error handler
76-
expect(result!.exception!.values!.length).equal(2);
77-
expect(result!.exception!.values![0].type).equal('TypeError');
78-
expect(result!.exception!.values![0].value).equal('two');
73+
expect(result!.exception!.values!.length).equal(3);
74+
expect(result!.exception!.values![0].type).equal('Error');
75+
expect(result!.exception!.values![0].value).equal('one');
7976
expect(result!.exception!.values![0].stacktrace).to.have.property('frames');
80-
expect(result!.exception!.values![1].type).equal('SyntaxError');
81-
expect(result!.exception!.values![1].value).equal('three');
77+
expect(result!.exception!.values![1].type).equal('TypeError');
78+
expect(result!.exception!.values![1].value).equal('two');
8279
expect(result!.exception!.values![1].stacktrace).to.have.property('frames');
80+
expect(result!.exception!.values![2].type).equal('SyntaxError');
81+
expect(result!.exception!.values![2].value).equal('three');
82+
expect(result!.exception!.values![2].stacktrace).to.have.property('frames');
8383
});
8484

85-
it('should allow to change walk key', () => {
85+
it('should allow to change walk key', async () => {
8686
linkedErrors = new LinkedErrors({
8787
key: 'reason',
8888
});
89-
const event = {
90-
exception: {
91-
values: [],
92-
},
93-
message: 'foo',
94-
};
9589

96-
const one: ExtendedError = new Error('one');
97-
const two: ExtendedError = new TypeError('two');
9890
const three: ExtendedError = new SyntaxError('three');
9991

100-
const originalException = one;
101-
one.reason = two;
92+
const two: ExtendedError = new TypeError('two');
10293
two.reason = three;
10394

95+
const one: ExtendedError = new Error('one');
96+
one.reason = two;
97+
98+
const originalException = one;
99+
const backend = new BrowserBackend({});
100+
const event = await backend.eventFromException(originalException);
104101
const result = linkedErrors.handler(event, {
105102
originalException,
106103
});
107104

108105
// It shouldn't include root exception, as it's already processed in the event by the main error handler
109-
expect(result!.exception!.values!.length).equal(2);
110-
expect(result!.exception!.values![0].type).equal('TypeError');
111-
expect(result!.exception!.values![0].value).equal('two');
106+
expect(result!.exception!.values!.length).equal(3);
107+
expect(result!.exception!.values![0].type).equal('Error');
108+
expect(result!.exception!.values![0].value).equal('one');
112109
expect(result!.exception!.values![0].stacktrace).to.have.property('frames');
113-
expect(result!.exception!.values![1].type).equal('SyntaxError');
114-
expect(result!.exception!.values![1].value).equal('three');
110+
expect(result!.exception!.values![1].type).equal('TypeError');
111+
expect(result!.exception!.values![1].value).equal('two');
115112
expect(result!.exception!.values![1].stacktrace).to.have.property('frames');
113+
expect(result!.exception!.values![2].type).equal('SyntaxError');
114+
expect(result!.exception!.values![2].value).equal('three');
115+
expect(result!.exception!.values![2].stacktrace).to.have.property('frames');
116116
});
117117
});
118118
});

0 commit comments

Comments
 (0)