forked from vercel/fetch-retry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrowser-test.js
36 lines (30 loc) · 818 Bytes
/
browser-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/* globals describe, it, expect, jasmine, beforeEach */
const fetchRetry = require('./index')
describe('fetch-retry', () => {
let fetchSpy
beforeEach(() => {
fetchSpy = jasmine.createSpy('fetch').and.callFake((url, opts) => {
let status = 200
let responseText = ''
if (url === 'http://success.com/200') {
status = 200
responseText = 'yay'
}
const res = {
status,
async text () {
return responseText
}
}
return Promise.resolve(res)
})
})
it('adds to pass fetch object', () => {
const ft = fetchRetry(window.fetch)
expect(ft).toBeTruthy()
})
it('passes on 200', async () => {
const res = await fetchRetry(fetchSpy)('http://success.com/200')
expect(await res.text()).toBe('yay')
})
})