Skip to content

Commit

Permalink
tests: add tests for res.location('back')
Browse files Browse the repository at this point in the history
closes #3292
closes #3293
  • Loading branch information
WORMSS authored and dougwilson committed May 7, 2017
1 parent 1b6e700 commit a13938e
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions test/res.location.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,63 @@ describe('res', function(){
.expect('Location', 'https://google.com?q=%A710')
.expect(200, done)
})

describe('when url is "back"', function () {
it('should set location from "Referer" header', function (done) {
var app = express()

app.use(function (req, res) {
res.location('back').end()
})

request(app)
.get('/')
.set('Referer', '/some/page.html')
.expect('Location', '/some/page.html')
.expect(200, done)
})

it('should set location from "Referrer" header', function (done) {
var app = express()

app.use(function (req, res) {
res.location('back').end()
})

request(app)
.get('/')
.set('Referrer', '/some/page.html')
.expect('Location', '/some/page.html')
.expect(200, done)
})

it('should prefer "Referrer" header', function (done) {
var app = express()

app.use(function (req, res) {
res.location('back').end()
})

request(app)
.get('/')
.set('Referer', '/some/page1.html')
.set('Referrer', '/some/page2.html')
.expect('Location', '/some/page2.html')
.expect(200, done)
})

it('should set the header to "/" without referrer', function (done) {
var app = express()

app.use(function (req, res) {
res.location('back').end()
})

request(app)
.get('/')
.expect('Location', '/')
.expect(200, done)
})
})
})
})

0 comments on commit a13938e

Please sign in to comment.