Skip to content

Commit 0049f86

Browse files
committed
nice
1 parent 04eb570 commit 0049f86

File tree

1 file changed

+34
-40
lines changed

1 file changed

+34
-40
lines changed

packages/signals/signals/src/core/signal-generators/network-gen/__tests__/network-generator.test.ts

Lines changed: 34 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { SignalEmitter } from '../../../emitter'
77
import { Response } from 'node-fetch'
88
import { sleep } from '@internal/test-helpers'
99
import { setLocation } from '../../../../test-helpers/set-location'
10+
import { NetworkSignal } from '@segment/analytics-signals-runtime'
1011

1112
// xhr tests are in integration tests
1213
describe(NetworkGenerator, () => {
@@ -140,47 +141,40 @@ describe(NetworkGenerator, () => {
140141
})
141142

142143
await sleep(100)
143-
expect(mockEmitter.emit.mock.calls).toMatchInlineSnapshot(`
144+
expect(
145+
mockEmitter.emit.mock.calls.flatMap((call) =>
146+
call.map((s: NetworkSignal) => s.data.action)
147+
)
148+
).toMatchInlineSnapshot(`
144149
[
145-
[
146-
{
147-
"data": {
148-
"action": "request",
149-
"contentType": "text/html",
150-
"data": "hello world",
151-
"method": "POST",
152-
"url": "http://localhost/api",
153-
},
154-
"metadata": {
155-
"filters": {
156-
"allowed": [],
157-
"disallowed": [],
158-
},
159-
},
160-
"type": "network",
161-
},
162-
],
163-
[
164-
{
165-
"data": {
166-
"action": "response",
167-
"contentType": "application/json",
168-
"data": {
169-
"data": "test",
170-
},
171-
"ok": true,
172-
"status": 200,
173-
"url": "http://localhost/api",
174-
},
175-
"metadata": {
176-
"filters": {
177-
"allowed": [],
178-
"disallowed": [],
179-
},
180-
},
181-
"type": "network",
182-
},
183-
],
150+
"request",
151+
"response",
152+
]
153+
`)
154+
155+
unregister()
156+
})
157+
158+
it('should emit response signal and request signal if no content-type', async () => {
159+
const mockEmitter = { emit: jest.fn() }
160+
const networkGenerator = new TestNetworkGenerator()
161+
const unregister = networkGenerator.register(
162+
mockEmitter as unknown as SignalEmitter
163+
)
164+
165+
await window.fetch(`/some-data?foo=123`, {
166+
method: 'GET',
167+
})
168+
169+
await sleep(100)
170+
expect(
171+
mockEmitter.emit.mock.calls.flatMap((call) =>
172+
call.map((s: NetworkSignal) => s.data.action)
173+
)
174+
).toMatchInlineSnapshot(`
175+
[
176+
"request",
177+
"response",
184178
]
185179
`)
186180

0 commit comments

Comments
 (0)