提交 bbb1a214 编写于 作者: M Mislav Marohnić

Merge pull request #217 from bryanrsmith/fetch-reject-on-error

Reject the Promise returned by fetch() when Request ctor throws
......@@ -284,14 +284,14 @@
self.Response = Response;
self.fetch = function(input, init) {
var request
if (Request.prototype.isPrototypeOf(input) && !init) {
request = input
} else {
request = new Request(input, init)
}
return new Promise(function(resolve, reject) {
var request
if (Request.prototype.isPrototypeOf(input) && !init) {
request = input
} else {
request = new Request(input, init)
}
var xhr = new XMLHttpRequest()
function responseURL() {
......
......@@ -55,6 +55,14 @@ test.skip('rejects promise for network error', function() {
})
})
test('rejects when Request constructor throws', function() {
return fetch('/request', { method: 'GET', body: 'invalid' }).then(function() {
assert(false, 'Invalid Request init was accepted')
}).catch(function(error) {
assert(error instanceof TypeError, 'Rejected with Error')
})
})
// https://fetch.spec.whatwg.org/#headers-class
suite('Headers', function() {
test('constructor copies headers', function() {
......@@ -601,8 +609,7 @@ suite('Methods', function() {
})
})
// TODO: Waiting to verify behavior
test.skip('GET with body throws TypeError', function() {
test('GET with body throws TypeError', function() {
assert.throw(function() {
new Request('', {
method: 'get',
......@@ -611,7 +618,7 @@ suite('Methods', function() {
}, TypeError)
})
test.skip('HEAD with body throws TypeError', function() {
test('HEAD with body throws TypeError', function() {
assert.throw(function() {
new Request('', {
method: 'head',
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册