Skip to content

Commit 8aa66d1

Browse files
authored
Merge pull request #531 from bugsnag/fix-delivery-fetch-tests
fix delivery-fetch tests
2 parents 849f4cd + ef3162f commit 8aa66d1

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

packages/delivery-fetch/tests/delivery.test.ts

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import createFetchDeliveryFactory from '../lib/delivery'
1414
const SENT_AT_FORMAT = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/
1515

1616
describe('Browser Delivery', () => {
17-
it('delivers a span', () => {
18-
const fetch = jest.fn(() => Promise.resolve({} as unknown as Response))
17+
it('delivers a span', async () => {
18+
const fetch = jest.fn(() => Promise.resolve({ status: 200, headers: new Headers() } as unknown as Response))
1919
const backgroundingListener = new ControllableBackgroundingListener()
2020
const clock = new IncrementingClock('2023-01-02T00:00:00.000Z')
2121

@@ -47,7 +47,7 @@ describe('Browser Delivery', () => {
4747

4848
const deliveryFactory = createFetchDeliveryFactory(fetch, clock, backgroundingListener)
4949
const delivery = deliveryFactory('/test')
50-
delivery.send(deliveryPayload)
50+
const response = await delivery.send(deliveryPayload)
5151

5252
expect(fetch).toHaveBeenCalledWith('/test', {
5353
method: 'POST',
@@ -60,10 +60,15 @@ describe('Browser Delivery', () => {
6060
'Bugsnag-Sent-At': new Date(clock.timeOrigin + 1).toISOString()
6161
}
6262
})
63+
64+
expect(response).toStrictEqual({
65+
state: 'success',
66+
samplingProbability: undefined
67+
})
6368
})
6469

65-
it('delivers a span with keepalive = true when the app is backgrounded', () => {
66-
const fetch = jest.fn(() => Promise.resolve({} as unknown as Response))
70+
it('delivers a span with keepalive = true when the app is backgrounded', async () => {
71+
const fetch = jest.fn(() => Promise.resolve({ status: 200, headers: new Headers() } as unknown as Response))
6772
const backgroundingListener = new ControllableBackgroundingListener()
6873

6974
const deliveryPayload: TracePayload = {
@@ -97,7 +102,7 @@ describe('Browser Delivery', () => {
97102

98103
backgroundingListener.sendToBackground()
99104

100-
delivery.send(deliveryPayload)
105+
const response = await delivery.send(deliveryPayload)
101106

102107
expect(fetch).toHaveBeenCalledWith('/test', {
103108
method: 'POST',
@@ -110,10 +115,15 @@ describe('Browser Delivery', () => {
110115
'Bugsnag-Sent-At': expect.stringMatching(SENT_AT_FORMAT)
111116
}
112117
})
118+
119+
expect(response).toStrictEqual({
120+
state: 'success',
121+
samplingProbability: undefined
122+
})
113123
})
114124

115-
it('delivers a span with keepalive = false when the app is returned to the foreground', () => {
116-
const fetch = jest.fn(() => Promise.resolve({} as unknown as Response))
125+
it('delivers a span with keepalive = false when the app is returned to the foreground', async () => {
126+
const fetch = jest.fn(() => Promise.resolve({ status: 200, headers: new Headers() } as unknown as Response))
117127
const backgroundingListener = new ControllableBackgroundingListener()
118128

119129
const deliveryPayload: TracePayload = {
@@ -148,7 +158,7 @@ describe('Browser Delivery', () => {
148158
backgroundingListener.sendToBackground()
149159
backgroundingListener.sendToForeground()
150160

151-
delivery.send(deliveryPayload)
161+
const response = await delivery.send(deliveryPayload)
152162

153163
expect(fetch).toHaveBeenCalledWith('/test', {
154164
method: 'POST',
@@ -161,6 +171,11 @@ describe('Browser Delivery', () => {
161171
'Bugsnag-Sent-At': expect.stringMatching(SENT_AT_FORMAT)
162172
}
163173
})
174+
175+
expect(response).toStrictEqual({
176+
state: 'success',
177+
samplingProbability: undefined
178+
})
164179
})
165180

166181
it.each([

0 commit comments

Comments
 (0)