Skip to content

Commit

Permalink
Fix statusText: undefined should give '' and null should give 'null'
Browse files Browse the repository at this point in the history
  • Loading branch information
tkrotoff authored and JakeChampion committed Jan 28, 2021
1 parent a8aa427 commit b5c8bd0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion fetch.js
Expand Up @@ -450,7 +450,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 : ''
this.statusText = options.statusText === undefined ? '' : '' + options.statusText
this.headers = new Headers(options.headers)
this.url = options.url || ''
this._initBody(bodyInit)
Expand Down
10 changes: 10 additions & 0 deletions test/test.js
Expand Up @@ -694,6 +694,16 @@ exercise.forEach(function(exerciseMode) {
assert.equal(r.headers.get('content-type'), 'text/plain')
})

test('construct with undefined statusText', function() {
var r = new Response('', {statusText: undefined})
assert.equal(r.statusText, '')
})

test('construct with null statusText', function() {
var r = new Response('', {statusText: null})
assert.equal(r.statusText, 'null')
})

test('init object as first argument', function() {
var r = new Response({
status: 201,
Expand Down

0 comments on commit b5c8bd0

Please sign in to comment.