Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change default statusText for Response #698

Merged
merged 3 commits into from May 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.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
23 changes: 15 additions & 8 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,19 +586,24 @@ 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})
assert.equal(res.status, 200)
assert.equal(res.statusText, 'OK')
assert.isTrue(res.ok)
})
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)
}
)

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