1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Update fetchWithCacheTests to use assert.rejects (#8334)

This commit is contained in:
Whymarrh Whitby 2020-04-14 13:03:33 -02:30 committed by GitHub
parent 656dc4cf18
commit 1775d9b163
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -71,12 +71,10 @@ describe('Fetch with cache', function () {
.delay(100) .delay(100)
.reply(200, '{"average": 4}') .reply(200, '{"average": 4}')
try { await assert.rejects(
await fetchWithCache('https://fetchwithcache.metamask.io/price', {}, { timeout: 20 }) () => fetchWithCache('https://fetchwithcache.metamask.io/price', {}, { timeout: 20 }),
assert.fail('Request should be aborted') { name: 'AbortError', message: 'Aborted' },
} catch (e) { )
assert.deepEqual(e.message, 'Aborted')
}
}) })
it('throws when the response is unsuccessful', async function () { it('throws when the response is unsuccessful', async function () {
@ -84,12 +82,9 @@ describe('Fetch with cache', function () {
.get('/price') .get('/price')
.reply(500, '{"average": 6}') .reply(500, '{"average": 6}')
try { await assert.rejects(
await fetchWithCache('https://fetchwithcache.metamask.io/price') () => fetchWithCache('https://fetchwithcache.metamask.io/price'),
assert.fail('Request should throw') )
} catch (e) {
assert.ok(e)
}
}) })
it('throws when a POST request is attempted', async function () { it('throws when a POST request is attempted', async function () {
@ -97,12 +92,9 @@ describe('Fetch with cache', function () {
.post('/price') .post('/price')
.reply(200, '{"average": 7}') .reply(200, '{"average": 7}')
try { await assert.rejects(
await fetchWithCache('https://fetchwithcache.metamask.io/price', { method: 'POST' }) () => fetchWithCache('https://fetchwithcache.metamask.io/price', { method: 'POST' }),
assert.fail('Request should throw') )
} catch (e) {
assert.ok(e)
}
}) })
it('throws when the request has a truthy body', async function () { it('throws when the request has a truthy body', async function () {
@ -110,12 +102,9 @@ describe('Fetch with cache', function () {
.get('/price') .get('/price')
.reply(200, '{"average": 8}') .reply(200, '{"average": 8}')
try { await assert.rejects(
await fetch('https://fetchwithcache.metamask.io/price', { body: 1 }) () => fetchWithCache('https://fetchwithcache.metamask.io/price', { body: 1 }),
assert.fail('Request should throw') )
} catch (e) {
assert.ok(e)
}
}) })
it('throws when the request has an invalid Content-Type header', async function () { it('throws when the request has an invalid Content-Type header', async function () {
@ -123,11 +112,9 @@ describe('Fetch with cache', function () {
.get('/price') .get('/price')
.reply(200, '{"average": 9}') .reply(200, '{"average": 9}')
try { await assert.rejects(
await fetch('https://fetchwithcache.metamask.io/price', { headers: { 'Content-Type': 'text/plain' } }) () => fetchWithCache('https://fetchwithcache.metamask.io/price', { headers: { 'Content-Type': 'text/plain' } }),
assert.fail('Request should throw') { message: 'fetchWithCache only supports JSON responses' },
} catch (e) { )
assert.ok(e)
}
}) })
}) })