Created
October 7, 2013 20:14
-
-
Save timestep/6874167 to your computer and use it in GitHub Desktop.
Sails Mocha Test. courtesy of xdissent from #sailsjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// In Sails app install test dependencies: | |
// $ npm install mocha supertest sails-memory --save-dev | |
// Create some tests in `test` folder in the app. | |
// Run `mocha` | |
var request = require('supertest'), | |
assert = require('assert'), | |
sails = require('sails'); | |
describe('foo', function () { | |
before(function (done) { | |
sails.lift({ | |
port: 0, | |
host: 'localhost', | |
adapters: {'default': 'memory'} | |
}, function (err) { | |
if (err) return done(err); | |
sails.models.foo.createEach([ | |
{name: 'one'}, | |
{name: 'two'}, | |
{name: 'three'} | |
], done); | |
}); | |
}); | |
after(function (done) { | |
sails.lower(done); | |
}); | |
describe('find', function () { | |
it('should show the home page', function (done) { | |
request(sails.express.server) | |
.get('/') | |
.expect(200, /Sails/, done); | |
}); | |
it('should return all foo models', function (done) { | |
request(sails.express.server) | |
.get('/foo') | |
.expect('Content-Type', /json/) | |
.expect(200, function (err, res) { | |
if (err) return done(err); | |
assert.equal(res.body.length, 3); | |
done(); | |
}); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment