/
githubmirror
/
express
Обзор
Документация
Войти
/
githubmirror
/
express
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
test/acceptance/cookies.js
70 строк
2 KB
Douglas Christopher Wilson
tests: use supertest to check response header values
11 май 2016, 09:50
11 май 2016, 09:50
12bc16e
Код
Авторство
О чём код?
var app = require('../../examples/cookies') , request = require('supertest'); var utils = require('../support/utils'); describe('cookies', function(){ describe('GET /', function(){ it('should have a form', function(done){ request(app) .get('/') .expect(/<form/, done); }) it('should respond with no cookies', function(done){ request(app) .get('/') .expect(utils.shouldNotHaveHeader('Set-Cookie')) .expect(200, done) }) it('should respond to cookie', function(done){ request(app) .post('/') .type('urlencoded') .send({ remember: 1 }) .expect(302, function(err, res){ if (err) return done(err) request(app) .get('/') .set('Cookie', res.headers['set-cookie'][0]) .expect(200, /Remembered/, done) }) }) }) describe('GET /forget', function(){ it('should clear cookie', function(done){ request(app) .post('/') .type('urlencoded') .send({ remember: 1 }) .expect(302, function(err, res){ if (err) return done(err) request(app) .get('/forget') .set('Cookie', res.headers['set-cookie'][0]) .expect('Set-Cookie', /remember=;/) .expect(302, done) }) }) }) describe('POST /', function(){ it('should set a cookie', function(done){ request(app) .post('/') .type('urlencoded') .send({ remember: 1 }) .expect('Set-Cookie', /remember=1/) .expect(302, done) }) it('should no set cookie w/o reminder', function(done){ request(app) .post('/') .send({}) .expect(utils.shouldNotHaveHeader('Set-Cookie')) .expect(302, done) }) }) })