Skip to content

refactor(server-tests): use sinon-chai and mocha.conf.js #500

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/templates/Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,8 @@ module.exports = function (grunt) {

mochaTest: {
options: {
reporter: 'spec'
reporter: 'spec',
require: 'mocha.conf.js'
},
src: ['server/**/*.spec.js']
},
Expand Down
3 changes: 2 additions & 1 deletion app/templates/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"socketio-jwt": "^2.0.2"<% } %>
},
"devDependencies": {
"chai-as-promised": "^4.1.1",
"grunt": "~0.4.4",
"grunt-autoprefixer": "~0.7.2",
"grunt-wiredep": "~1.8.0",
Expand Down Expand Up @@ -86,7 +87,7 @@
"karma": "~0.12.9",
"karma-ng-html2js-preprocessor": "~0.1.0",
"supertest": "~0.11.0",
"should": "~3.3.1"
"sinon-chai": "^2.5.0"
},
"engines": {
"node": ">=0.10.0"
Expand Down
12 changes: 12 additions & 0 deletions app/templates/mocha.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

var chai = require('chai');
var sinon = require('sinon');
var sinonChai = require('sinon-chai');
var chaiAsPromised = require('chai-as-promised');

global.expect = chai.expect;
global.assert = chai.assert;
chai.should();
chai.use(sinonChai);
chai.use(chaiAsPromised);
3 changes: 1 addition & 2 deletions app/templates/server/api/thing/thing.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

var should = require('should');
var app = require('../../app');
var request = require('supertest');

Expand All @@ -13,7 +12,7 @@ describe('GET /api/things', function() {
.expect('Content-Type', /json/)
.end(function(err, res) {
if (err) return done(err);
res.body.should.be.instanceof(Array);
res.body.should.be.instanceOf(Array);
done();
});
});
Expand Down
20 changes: 8 additions & 12 deletions app/templates/server/api/user(auth)/user.model.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

var should = require('should');
var app = require('../../app');
var User = require('./user.model');

Expand All @@ -12,17 +11,14 @@ var user = new User({
});

describe('User Model', function() {
before(function(done) {
// Clear users before testing
User.remove().exec().then(function() {
done();
});

// Clear users before testing
before(function() {
return User.remove().exec();
});

afterEach(function(done) {
User.remove().exec().then(function() {
done();
});
afterEach(function() {
return User.remove().exec();
});

it('should begin with no users', function(done) {
Expand All @@ -36,7 +32,7 @@ describe('User Model', function() {
user.save(function() {
var userDup = new User(user);
userDup.save(function(err) {
should.exist(err);
err.should.be.instanceOf(Error);
done();
});
});
Expand All @@ -45,7 +41,7 @@ describe('User Model', function() {
it('should fail when saving without an email', function(done) {
user.email = '';
user.save(function(err) {
should.exist(err);
err.should.be.instanceOf(Error);
done();
});
});
Expand Down
5 changes: 2 additions & 3 deletions endpoint/templates/name.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

var should = require('should');
var app = require('../../app');
var request = require('supertest');

Expand All @@ -13,8 +12,8 @@ describe('GET <%= route %>', function() {
.expect('Content-Type', /json/)
.end(function(err, res) {
if (err) return done(err);
res.body.should.be.instanceof(Array);
res.body.should.be.instanceOf(Array);
done();
});
});
});
});
3 changes: 2 additions & 1 deletion test/fixtures/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"socketio-jwt": "^2.0.2"
},
"devDependencies": {
"chai-as-promised": "^4.1.1",
"grunt": "~0.4.4",
"grunt-autoprefixer": "~0.7.2",
"grunt-wiredep": "~1.8.0",
Expand Down Expand Up @@ -86,7 +87,7 @@
"karma": "~0.12.9",
"karma-ng-html2js-preprocessor": "~0.1.0",
"supertest": "~0.11.0",
"should": "~3.3.1"
"sinon-chai": "^2.5.0"
},
"engines": {
"node": ">=0.10.0"
Expand Down