Permalink
Browse files

add tests

  • Loading branch information...
1 parent 9708358 commit b13d29872a2d14d360f84f5e9dfaa779e7b860fc @mgutz mgutz committed Jan 16, 2013
Showing with 92 additions and 7 deletions.
  1. +21 −0 Gruntfile.js
  2. +13 −4 README.md
  3. +8 −2 example/app.js
  4. +4 −1 package.json
  5. +46 −0 tests/handlebarsSpecs.js
View
@@ -0,0 +1,21 @@
+var os = require('os');
+var platform = os.platform();
+var isWindows = platform.indexOf('win') === 0;
+var isLinux = platform === 'linux';
+var Path = require('path')
+
+
+module.exports = function(grunt) {
+ grunt.loadNpmTasks('grunt-simple-mocha');
+
+ grunt.initConfig({
+ simplemocha: {
+ all: {
+ src: 'tests/**/*Specs.js'
+ }
+ }
+ });
+
+ // Runs tests by default.
+ grunt.registerTask('default', 'simplemocha');
+};
View
@@ -28,9 +28,8 @@ Options for `#express3`
Partials may use any extension, which is better for syntax highlighting.
-## Syntax
-
+## Syntax
To mark where layout should insert page,
@@ -60,10 +59,10 @@ There are three ways to use a layout, listed in the order in which they are chec
veggies: veggies,
layout: 'layout/veggie'
});
-
+
This option also allows for default layout suppression by passing in a falsey Javascript value as the value of the `layout` property:
-```
+```
res.render('veggies', {
title: 'My favorite veggies',
veggies: veggies,
@@ -118,6 +117,16 @@ To run example project
npm install -d
node example/app.js
+
+## Testing
+
+Running tests requires [grunt](http://gruntjs.com/)
+
+ npm install -g grunt-cli
+ npm install -d
+ grunt
+
+
## Credits
Inspiration and code from [donpark/hbs](https://github.com/donpark/hbs)
View
@@ -45,5 +45,11 @@ app.get('/veggies', function(req, res) {
});
});
-app.listen(3000);
-console.log('Express server listening on port 3000');
+
+if (require.main === module) {
+ app.listen(3000);
+ console.log('Express server listening on port 3000');
+}
+else {
+ module.exports = app;
+}
View
@@ -14,7 +14,10 @@
"author": "Mario Gutierrez (mario@mgutz.com)",
"license": "MIT",
"devDependencies": {
- "express": "~3.0.0"
+ "express": "~3.0.6",
+ "supertest": "~0.5.1",
+ "grunt": "~0.4.0rc5",
+ "grunt-simple-mocha": "git://github.com/yaymukund/grunt-simple-mocha.git"
},
"dependencies": {
"handlebars": "~1.0.7"
@@ -0,0 +1,46 @@
+var request = require('supertest');
+var app = require('../example/app');
+
+describe('express-hbs', function() {
+
+ describe('File provider', function() {
+
+ it('should render using default layout', function(done) {
+ request(app)
+ .get('/')
+ .expect(/DEFAULT LAYOUT/, done);
+ });
+
+ it('should render layout declared in markup', function(done) {
+ request(app)
+ .get('/fruits')
+ .expect(/DECLARATIVE LAYOUT/, done);
+ });
+
+ it('should render layout specified as locals', function(done) {
+ request(app)
+ .get('/veggies')
+ .expect(/PROGRAMMATIC LAYOUT/, done);
+ });
+
+ it('should render partial', function(done) {
+ request(app)
+ .get('/veggies')
+ .expect(/jquery\.js/, done);
+ });
+
+ it('should render block', function(done) {
+ request(app)
+ .get('/')
+ .expect(/color: blue/, done);
+ });
+
+ it('should replace {{body}}', function(done) {
+ request(app)
+ .get('/')
+ .expect(/Vegetables/, done);
+ });
+
+ });
+
+});

0 comments on commit b13d298

Please sign in to comment.