Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added test for request-level exposure

  • Loading branch information...
commit 836cea96236f9260724f74aba36342a95ebfcc20 1 parent a33cbf8
@jonpacker jonpacker authored
Showing with 29 additions and 2 deletions.
  1. +1 −0  package.json
  2. +28 −2 test/express-expose.test.js
View
1  package.json
@@ -8,6 +8,7 @@
, "mocha": "*"
, "should": "*"
, "jade": "*"
+ , "supertest": "*"
}
, "main": "index"
}
View
30 test/express-expose.test.js
@@ -7,7 +7,8 @@ var express = require('express')
, expose = require('../')
, assert = require('assert')
, should = require('should')
- , vm = require('vm');
+ , vm = require('vm')
+ , request = require('supertest');
module.exports = {
'test app.expose(name)': function(){
@@ -132,5 +133,30 @@ module.exports = {
vm.runInNewContext(js, scope);
scope.sub(8,7).should.equal(1);
scope.should.not.have.property('add');
- }
+ },
+
+ 'test res.expose(str)': function(done){
+ var app = express();
+ app.set('view engine', 'jade');
+ app.set('views', __dirname + '/views');
+
+ app.expose('var user = { name: "tj" };')
+
+ app.get('/', function(req, res) {
+ res.expose('var lang = "en";');
+ res.render('index');
+ });
+
+ request(app)
+ .get('/')
+ .end(function(err, res) {
+ if (err) throw err;
+
+ var scope = {};
+ vm.runInNewContext(res.text, scope);
+ scope.user.name.should.equal('tj');
+ scope.lang.should.equal('en');
+ done();
+ });
+ },
};
Please sign in to comment.
Something went wrong with that request. Please try again.