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 fileTake it
The walk stopped after 200 commits: lines older than 0f3a764 point at it.
Evaulating routes in context to their given request instancevisionmediabefore adoption0f3a764
lines 1–4why, one step back12describe 'Express'3 before_each4 reset()Merge branch 'plugin-halt'visionmediabefore adoption1879648
lines 5–8why, one step back5 hooks = require('express/plugins/hooks')6 use(hooks.Hooks)7 hooks.callbacks.before = []8 hooks.callbacks.after = []Evaulating routes in context to their given request instancevisionmediabefore adoption0f3a764
lines 9–13why, one step back9 end10 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 back14 GLOBAL.before(function(){15 this.response.body = 'foo'Evaulating routes in context to their given request instancevisionmediabefore adoption0f3a764
line 16why, one step back16 })Hooks are now called in context to the requestvisionmediabefore adoption202c74d
lines 17–18why, one step back17 GLOBAL.before(function(){18 this.response.body += 'bar'Evaulating routes in context to their given request instancevisionmediabefore adoption0f3a764
lines 19–21why, one step back19 })20 get('/user', function(){})21 get('/user').body.should.eql 'foobar'Merge branch 'plugin-halt'visionmediabefore adoption1879648
lines 22–30why, one step back22 end23 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!'Evaulating routes in context to their given request instancevisionmediabefore adoption0f3a764
lines 31–36why, one step back31 end32 end33 34 describe 'after()'35 it 'should be called after every request'36 var bodyHooks are now called in context to the requestvisionmediabefore adoption202c74d
lines 37–38why, one step back37 GLOBAL.after(function(){38 body = this.response.bodyEvaulating routes in context to their given request instancevisionmediabefore adoption0f3a764
lines 39–46why, one step back39 })40 get('/user', function(){ return 'test' })41 get('/user').body.should.eql 'test'42 body.should.eql 'test'43 end44 end45 end46end