|
1 | 1 | import { BrowserClient } from '@sentry/browser';
|
2 | 2 | import { Hub, makeMain } from '@sentry/hub';
|
3 | 3 |
|
4 |
| -import { Span, Transaction } from '../../src'; |
| 4 | +import { Span, SpanStatus, Transaction } from '../../src'; |
5 | 5 | import { _fetchCallback, FetchData, registerRequestInstrumentation } from '../../src/browser/request';
|
6 | 6 | import { addExtensionMethods } from '../../src/hubextensions';
|
7 | 7 |
|
@@ -157,4 +157,33 @@ describe('_fetchCallback()', () => {
|
157 | 157 | fail('Transaction does not have span recorder');
|
158 | 158 | }
|
159 | 159 | });
|
| 160 | + |
| 161 | + it('sets response status on finish', () => { |
| 162 | + const shouldCreateSpan = (_: string): boolean => true; |
| 163 | + const data: FetchData = { |
| 164 | + args: ['/users'], |
| 165 | + fetchData: { |
| 166 | + method: 'GET', |
| 167 | + url: '/users', |
| 168 | + }, |
| 169 | + startTimestamp: 1595509730275, |
| 170 | + }; |
| 171 | + const spans: Record<string, Span> = {}; |
| 172 | + |
| 173 | + // Start fetch request |
| 174 | + _fetchCallback(data, shouldCreateSpan, spans); |
| 175 | + |
| 176 | + const newData = { |
| 177 | + ...data, |
| 178 | + endTimestamp: data.startTimestamp + 12343234, |
| 179 | + response: { status: 404 } as Response, |
| 180 | + }; |
| 181 | + // End fetch request |
| 182 | + _fetchCallback(newData, shouldCreateSpan, spans); |
| 183 | + if (transaction.spanRecorder) { |
| 184 | + expect(transaction.spanRecorder.spans[1].status).toBe(SpanStatus.fromHttpCode(404)); |
| 185 | + } else { |
| 186 | + fail('Transaction does not have span recorder'); |
| 187 | + } |
| 188 | + }); |
160 | 189 | });
|
0 commit comments