From e428559a68f5c9d445bf2fb5a91fb3f7e35b2f5d Mon Sep 17 00:00:00 2001 From: Zirak Date: Wed, 15 Oct 2014 23:28:25 +0300 Subject: [PATCH] Fixed uncaught error when a body was consumed more than once. Ammended tets to also check error message, not just type. --- fetch.js | 2 +- test/test.js | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/fetch.js b/fetch.js index c788aa91..77ed3ee3 100644 --- a/fetch.js +++ b/fetch.js @@ -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 } diff --git a/test/test.js b/test/test.js index 64fcedad..adcdd37a 100644 --- a/test/test.js +++ b/test/test.js @@ -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() }) })