Skip to content

Commit

Permalink
Change default statusText for Response
Browse files Browse the repository at this point in the history
  • Loading branch information
CrOrc committed Mar 28, 2019
1 parent 3674c98 commit c69500b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 5 deletions.
2 changes: 1 addition & 1 deletion fetch.js
Expand Up @@ -391,7 +391,7 @@ export function Response(bodyInit, options) {
this.type = 'default'
this.status = options.status === undefined ? 200 : options.status

This comment was marked as spam.

Copy link
@Jleland8044

Jleland8044 Mar 5, 2020

Change

this.ok = this.status >= 200 && this.status < 300
this.statusText = 'statusText' in options ? options.statusText : 'OK'
this.statusText = 'statusText' in options ? options.statusText : ''
this.headers = new Headers(options.headers)
this.url = options.url || ''
this._initBody(bodyInit)
Expand Down
51 changes: 47 additions & 4 deletions test/test.js
Expand Up @@ -123,6 +123,8 @@ exercise.forEach(function(exerciseMode) {
var nativeEdge = /Edge\//.test(navigator.userAgent) && exerciseMode === 'native'
var firefox = navigator.userAgent.match(/Firefox\/(\d+)/)
var brokenFF = firefox && firefox[1] <= 56 && exerciseMode === 'native'
var emptyDefaultStatusText =
exerciseMode !== 'native' || (exerciseMode === 'native' && (Chrome || (firefox && firefox[1] >= 67)))
var polyfillFirefox = firefox && exerciseMode === 'polyfill'
var omitSafari =
Safari && exerciseMode === 'native' && navigator.userAgent.match(/Version\/(\d+\.\d+)/)[1] <= '11.1'
Expand Down Expand Up @@ -584,20 +586,61 @@ exercise.forEach(function(exerciseMode) {

// https://fetch.spec.whatwg.org/#response-class
suite('Response', function() {
test('default status is 200 OK', function() {
featureDependent(test, emptyDefaultStatusText, "default status is 200 ''", function() {
var res = new Response()
assert.equal(res.status, 200)
assert.equal(res.statusText, 'OK')
assert.equal(res.statusText, '')
assert.isTrue(res.ok)
})

test('default status is 200 OK when an explicit undefined status code is passed', function() {
var res = new Response('', {status: undefined})
featureDependent(
test,
emptyDefaultStatusText,
"default status is 200 '' when an explicit undefined status code is passed",
function() {
var res = new Response('', {status: undefined})
assert.equal(res.status, 200)
assert.equal(res.statusText, '')
assert.isTrue(res.ok)
}
)
featureDependent(test, !emptyDefaultStatusText, 'default status is 200 OK', function() {
var res = new Response()
assert.equal(res.status, 200)
assert.equal(res.statusText, 'OK')
assert.isTrue(res.ok)
})

featureDependent(
test,
!emptyDefaultStatusText,
'default status is 200 OK when an explicit undefined status code is passed',
function() {
var res = new Response('', {status: undefined})
assert.equal(res.status, 200)
assert.equal(res.statusText, 'OK')
assert.isTrue(res.ok)
}
)
featureDependent(test, exerciseMode !== 'native', "default status is 200 ''", function() {
var res = new Response()
assert.equal(res.status, 200)
assert.equal(res.statusText, '')
assert.isTrue(res.ok)
})

featureDependent(
test,
exerciseMode !== 'native',
"default status is 200 '' when an explicit undefined status code is passed",
function() {
var res = new Response('', {status: undefined})
assert.equal(res.status, 200)
assert.equal(res.statusText, '')
assert.isTrue(res.ok)
}
)

testBodyExtract(function(body) {
return new Response(body)
})
Expand Down

0 comments on commit c69500b

Please sign in to comment.