Skip to content
Myr

spec.plugins.hooks.js

This file

Path

spec/spec.plugins.hooks.js

46 lines · 1.1 KiB · JavaScript

Last changed by

Merge branch 'plugin-halt'visionmediabefore adoption1879648

History of this file

Take it

The walk stopped after 200 commits: lines older than 48bea03 point at it.

Fixing cookie specsvisionmediabefore adoption48bea03

lines 1–4why, one step back
1
2describe 'Express'3 before_each4 reset()

Merge branch 'plugin-halt'visionmediabefore adoption1879648

lines 5–8why, one step back
5 hooks = require('express/plugins/hooks')
6 use(hooks.Hooks)7 hooks.callbacks.before = []8 hooks.callbacks.after = []

Fixing cookie specsvisionmediabefore adoption48bea03

lines 9–13why, one step back
9 end
10 11 describe 'Hooks'12 describe 'before()'13 it 'should be called before every request'

Hooks are now called in context to the requestvisionmediabefore adoption202c74d

lines 14–15why, one step back
14 GLOBAL.before(function(){
15 this.response.body = 'foo'

Fixing cookie specsvisionmediabefore adoption48bea03

line 16why, one step back
16 })

Hooks are now called in context to the requestvisionmediabefore adoption202c74d

lines 17–18why, one step back
17 GLOBAL.before(function(){
18 this.response.body += 'bar'

Fixing cookie specsvisionmediabefore adoption48bea03

lines 19–21why, one step back
19 })
20 get('/user', function(){})21 get('/user').body.should.eql 'foobar'

Merge branch 'plugin-halt'visionmediabefore adoption1879648

lines 22–30why, one step back
22 end
23 24 it 'should be able to halt the request'25 GLOBAL.before(function(){26 this.halt(404, 'woo!')27 })28 get('/user', function(){ return 'fail' })29 get('/user').status.should.eql 40430 get('/user').body.should.eql 'woo!'

Fixing cookie specsvisionmediabefore adoption48bea03

lines 31–36why, one step back
31 end
32 end33 34 describe 'after()'35 it 'should be called after every request'36 var body

Hooks are now called in context to the requestvisionmediabefore adoption202c74d

lines 37–38why, one step back
37 GLOBAL.after(function(){
38 body = this.response.body

Fixing cookie specsvisionmediabefore adoption48bea03

lines 39–46why, one step back
39 })
40 get('/user', function(){ return 'test' })41 get('/user').body.should.eql 'test'42 body.should.eql 'test'43 end44 end45 end46end