Skip to content

Commit

Permalink
Merge pull request #10 from Zirak/master
Browse files Browse the repository at this point in the history
Use of `Promise.reject` as a constructor
  • Loading branch information
dgraham committed Oct 15, 2014
2 parents ea501dc + e428559 commit d0f2611
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
9 changes: 6 additions & 3 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})

0 comments on commit d0f2611

Please sign in to comment.