test: added cookie parser test

This commit is contained in:
Roberto Tonino 2021-04-09 19:16:25 +02:00
parent 78d70b7369
commit e2c79f6ee6

View file

@ -0,0 +1,30 @@
// Taken from https://github.com/visionmedia/supertest
import request from 'supertest'
import express from 'express'
import cookieParser from 'cookie-parser'
describe('request.agent(app)', function () {
const app = express()
app.use(cookieParser())
app.get('/', (_, res) => {
res.cookie('cookie', 'hey')
res.send()
})
app.get('/return', (req, res) => {
if (req.cookies.cookie) res.send(req.cookies.cookie)
else res.send(':(')
})
const agent = request.agent(app)
it('should save cookies', done => {
agent.get('/').expect('set-cookie', 'cookie=hey; Path=/', done)
})
it('should send cookies', done => {
agent.get('/return').expect('hey', done)
})
})