video-ad-sdk
Version:
VAST/VPAID SDK that allows video ads to be played on top of any player
34 lines (25 loc) • 978 B
text/typescript
import {fetch} from '../fetch'
test("fetch must add credentials 'include' to the request options", async () => {
const successResponse = new Response(null, {status: 200})
global.fetch = jest.fn(() => Promise.resolve(successResponse))
const response = await fetch('http://example.com')
expect(global.fetch).toHaveBeenCalledWith(
'http://example.com',
expect.objectContaining({credentials: 'include'})
)
expect(response).toEqual(successResponse)
})
test("fetch must throw an error if the response's status is above 399", async () => {
const forbiddenResponse = new Response(null, {
status: 403,
statusText: 'forbidden request'
})
global.fetch = jest.fn(() => Promise.resolve(forbiddenResponse))
try {
await fetch('http://example.com')
throw new Error('should have thrown already')
} catch (error: any) {
expect(error.message).toBe(forbiddenResponse.statusText)
expect(error.response).toEqual(forbiddenResponse)
}
})