Permalink
Browse files

Add tests.

  • Loading branch information...
1 parent 6469326 commit 5872c95d91e04074791ab0c67f96116c0ea73b8b @jharding committed Sep 12, 2012
Showing with 38 additions and 1 deletion.
  1. +5 −1 package.json
  2. +33 −0 test/test_express_csrf_local.js
View
@@ -25,7 +25,11 @@
"node": ">=0.6.0"
},
"devDependencies": {
- "express": "*"
+ "connect": "~2.4.5",
+ "nodeunit": "~0.7.4"
+ },
+ "scripts": {
+ "test": "./node_modules/nodeunit/bin/nodeunit test/test_express_csrf_local.js"
},
"keywords": [
"express",
@@ -0,0 +1,33 @@
+var connect = require('connect');
+var csrfLocal = require('../index');
+
+var noop = function() {};
+
+module.exports['express-csrf-local'] = {
+ setUp: function(callback) {
+ this.req = { session: {}, method: 'GET' };
+ this.res = { locals: {} };
+
+ this.csrf = connect.csrf();
+
+ callback();
+ },
+
+ 'test with custom name': function(test) {
+ this.csrf(this.req, this.res, noop);
+ csrfLocal('custom')(this.req, this.res, noop);
+
+ test.expect(1);
+ test.equals(this.req.session._csrf, this.res.locals.custom);
+ test.done();
+ },
+
+ 'test without custom name': function(test) {
+ this.csrf(this.req, this.res, noop);
+ csrfLocal()(this.req, this.res, noop);
+
+ test.expect(1);
+ test.equals(this.req.session._csrf, this.res.locals.token);
+ test.done();
+ }
+};

0 comments on commit 5872c95

Please sign in to comment.