2020-06-10 04:04:23 +02:00
|
|
|
import { ALL_EMOJI, ALL_EMOJI_NO_ETAG, basicAfterEach, basicBeforeEach, truncatedEmoji } from '../shared'
|
2020-06-07 04:36:45 +02:00
|
|
|
|
|
|
|
describe('basic fetch tests', () => {
|
2020-06-10 04:04:23 +02:00
|
|
|
beforeEach(basicBeforeEach)
|
|
|
|
afterEach(basicAfterEach)
|
|
|
|
|
2024-03-09 22:11:22 +01:00
|
|
|
test('make sure fetch-mock is working correctly', async () => {
|
2024-03-09 18:13:23 +01:00
|
|
|
expect(fetch.calls().length).toBe(0)
|
2020-06-07 04:36:45 +02:00
|
|
|
const resp = await fetch(ALL_EMOJI)
|
|
|
|
expect(resp.headers.get('etag')).toBe('W/xxx')
|
2023-11-11 17:12:20 +01:00
|
|
|
expect(await (resp).json()).toEqual(truncatedEmoji)
|
2024-03-09 18:13:23 +01:00
|
|
|
expect(fetch.calls().length).toBe(1)
|
|
|
|
expect(fetch.lastUrl()).toBe(ALL_EMOJI)
|
|
|
|
expect(fetch.lastOptions()).toBe(undefined)
|
2020-06-07 04:36:45 +02:00
|
|
|
})
|
|
|
|
|
2024-03-09 22:11:22 +01:00
|
|
|
test('make sure fetch-mock is working correctly 2', async () => {
|
2024-03-09 18:13:23 +01:00
|
|
|
expect(fetch.calls().length).toBe(0)
|
2020-06-07 04:36:45 +02:00
|
|
|
const resp = await fetch(ALL_EMOJI_NO_ETAG)
|
|
|
|
expect(resp.headers.get('etag')).toBeFalsy()
|
2023-11-11 17:12:20 +01:00
|
|
|
expect(await (resp).json()).toEqual(truncatedEmoji)
|
2024-03-09 18:13:23 +01:00
|
|
|
expect(fetch.calls().length).toBe(1)
|
|
|
|
expect(fetch.lastUrl()).toBe(ALL_EMOJI_NO_ETAG)
|
|
|
|
expect(fetch.lastOptions()).toBe(undefined)
|
2020-06-07 04:36:45 +02:00
|
|
|
})
|
|
|
|
|
2024-03-09 22:11:22 +01:00
|
|
|
test('make sure fetch-mock is working correctly 3', async () => {
|
2024-03-09 18:13:23 +01:00
|
|
|
expect(fetch.calls().length).toBe(0)
|
2020-06-07 04:36:45 +02:00
|
|
|
const resp = await fetch(ALL_EMOJI, { method: 'HEAD' })
|
|
|
|
expect(resp.headers.get('etag')).toBe('W/xxx')
|
2024-03-09 18:13:23 +01:00
|
|
|
expect(fetch.calls().length).toBe(1)
|
|
|
|
expect(fetch.lastUrl()).toBe(ALL_EMOJI)
|
|
|
|
expect(fetch.lastOptions()).toEqual({ method: 'HEAD' })
|
2020-06-07 04:36:45 +02:00
|
|
|
})
|
|
|
|
})
|