Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
danieljackins committed Jan 10, 2024
1 parent 966e675 commit 7cd4a09
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions packages/browser/src/browser/__tests__/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ const googleAnalytics: Plugin = {
type: 'destination',
}

const slowPlugin: Plugin = {
...xt,
name: 'Slow Plugin',
type: 'destination',
track: async (ctx) => {
await sleep(3000)
return ctx
},
}

const enrichBilling: Plugin = {
...xt,
name: 'Billing Enrichment',
Expand Down Expand Up @@ -574,6 +584,34 @@ describe('Dispatch', () => {
expect(segmentSpy).toHaveBeenCalledWith(boo)
})

it('dispatching to Segmentio not blocked by other destinations', async () => {
const [ajs] = await AnalyticsBrowser.load({
writeKey,
plugins: [slowPlugin],
})

const segmentio = ajs.queue.plugins.find((p) => p.name === 'Segment.io')
const segmentSpy = jest.spyOn(segmentio!, 'track')

await Promise.race([
ajs.track(
'Boo!',
{
total: 25,
userId: '👻',
},
{
integrations: {
All: true,
},
}
),
sleep(100),
])

expect(segmentSpy).toHaveBeenCalled()
})

it('enriches events before dispatching', async () => {
const [ajs] = await AnalyticsBrowser.load({
writeKey,
Expand Down

0 comments on commit 7cd4a09

Please sign in to comment.