Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
benjackwhite committed Aug 8, 2024
1 parent 0b9a455 commit a83c28a
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/__tests__/request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,18 @@ describe('request', () => {
request(
createRequest({
url: 'https://any.posthog-instance.com/',
headers: {
'x-header': 'value',
},
})
)
expect(mockedXHR.open).toHaveBeenCalledWith(
'GET',
'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 () => {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit a83c28a

Please sign in to comment.