Fixed uncaught error when a body was consumed more than once.

Ammended tets to also check error message, not just type.
This commit is contained in:
Zirak 2014-10-15 23:28:25 +03:00
Родитель ea501dc322
Коммит e428559a68
2 изменённых файлов: 7 добавлений и 4 удалений

Просмотреть файл

@ -63,7 +63,7 @@
function consumed(body) {
if (body.bodyUsed) {
return new Promise.reject(new TypeError('Body already consumed'))
return Promise.reject(new TypeError('Body already consumed'))
}
body.bodyUsed = true
}

Просмотреть файл

@ -150,32 +150,35 @@ asyncTest('post sets content-type header', 1, function() {
})
})
asyncTest('rejects blob promise after body is consumed', 1, function() {
asyncTest('rejects blob promise after body is consumed', 2, function() {
fetch('/hello').then(function(response) {
response.blob()
return response.blob()
}).catch(function(error) {
ok(error instanceof TypeError, 'Promise rejected after body consumed')
ok(error.message === 'Body already consumed', 'Promise rejected for incorrect reason')
start()
})
})
asyncTest('rejects json promise after body is consumed', 1, function() {
asyncTest('rejects json promise after body is consumed', 2, function() {
fetch('/json').then(function(response) {
response.json()
return response.json()
}).catch(function(error) {
ok(error instanceof TypeError, 'Promise rejected after body consumed')
ok(error.message === 'Body already consumed', 'Promise rejected for incorrect reason')
start()
})
})
asyncTest('rejects text promise after body is consumed', 1, function() {
asyncTest('rejects text promise after body is consumed', 2, function() {
fetch('/hello').then(function(response) {
response.text()
return response.text()
}).catch(function(error) {
ok(error instanceof TypeError, 'Promise rejected after body consumed')
ok(error.message === 'Body already consumed', 'Promise rejected for incorrect reason')
start()
})
})