From a83c28ae8c16522c7141c3aa1ba351c145e1bc56 Mon Sep 17 00:00:00 2001 From: Ben White Date: Thu, 8 Aug 2024 10:14:10 +0200 Subject: [PATCH] Add tests --- src/__tests__/request.test.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/__tests__/request.test.ts b/src/__tests__/request.test.ts index 9830f4977..57e22abc3 100644 --- a/src/__tests__/request.test.ts +++ b/src/__tests__/request.test.ts @@ -68,6 +68,9 @@ describe('request', () => { request( createRequest({ url: 'https://any.posthog-instance.com/', + headers: { + 'x-header': 'value', + }, }) ) expect(mockedXHR.open).toHaveBeenCalledWith( @@ -75,6 +78,8 @@ describe('request', () => { 'https://any.posthog-instance.com/?_=1700000000000&ver=1.23.45', true ) + + expect(mockedXHR.setRequestHeader).toHaveBeenCalledWith('x-header', 'value') }) it('calls the on callback handler when successful', async () => { @@ -114,7 +119,16 @@ describe('request', () => { }) it('performs the request with default params', () => { - request(createRequest()) + request( + createRequest({ + headers: { + 'x-header': 'value', + }, + }) + ) + + const headers = mockedFetch.mock.calls[0][1].headers as Headers + expect(headers.get('x-header')).toEqual('value') expect(mockedFetch).toHaveBeenCalledWith(`https://any.posthog-instance.com?ver=1.23.45&_=1700000000000`, { body: undefined,