Skip to content

Commit

Permalink
fix: do not throw if request fails
Browse files Browse the repository at this point in the history
fix #11
  • Loading branch information
Barbapapazes committed Jul 18, 2024
1 parent 89c863c commit 37ffafb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,5 @@ export function sendEvent(
body: JSON.stringify(payload),
}).then(() => {
callback?.()
})
}).catch(() => {})
}
6 changes: 6 additions & 0 deletions test/event.dom.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,10 @@ describe('`sendEvent`', () => {

expect(callback).not.toHaveBeenCalled()
})

it('should not throw if the request fails', async () => {
vi.spyOn(window, 'fetch').mockRejectedValue(new Error('Failed to fetch'))

await expect(sendEvent('https://example.com', eventPayload)).resolves.not.toThrow()
})
})

0 comments on commit 37ffafb

Please sign in to comment.