From b3c43b60cd574133343312027afaf1cf34c5e6b1 Mon Sep 17 00:00:00 2001 From: David Cheung Date: Fri, 21 Oct 2016 11:17:02 -0400 Subject: [PATCH] make test individually runable previously when you do something like mocha test/model.test.js you would get an error like "assert is not a function" --- test/access-token.test.js | 8 +++++++- test/app.test.js | 8 ++++++-- test/mocha.opts | 1 + test/model.test.js | 6 +++++- test/support.js | 5 ----- 5 files changed, 19 insertions(+), 9 deletions(-) create mode 100644 test/mocha.opts diff --git a/test/access-token.test.js b/test/access-token.test.js index 50d8d91d..ef49dc5b 100644 --- a/test/access-token.test.js +++ b/test/access-token.test.js @@ -16,7 +16,11 @@ Token.attachTo(ds); var ACL = loopback.ACL; describe('loopback.token(options)', function() { - beforeEach(createTestingToken); + var app; + beforeEach(function(done) { + app = loopback(); + createTestingToken.call(this, done); + }); it('should populate req.token from the query string', function(done) { createTestAppAndRequest(this.token, done) @@ -428,7 +432,9 @@ describe('AccessToken', function() { }); describe('app.enableAuth()', function() { + var app; beforeEach(function setupAuthWithModels() { + app = loopback(); app.enableAuth({ dataSource: ds }); }); beforeEach(createTestingToken); diff --git a/test/app.test.js b/test/app.test.js index 39f720a8..8e210ca9 100644 --- a/test/app.test.js +++ b/test/app.test.js @@ -16,11 +16,15 @@ var expect = require('chai').expect; var it = require('./util/it'); describe('app', function() { + var app; + beforeEach(function() { + app = loopback(); + }); + describe.onServer('.middleware(phase, handler)', function() { - var app, steps; + var steps; beforeEach(function setup() { - app = loopback(); steps = []; }); diff --git a/test/mocha.opts b/test/mocha.opts new file mode 100644 index 00000000..06ec4225 --- /dev/null +++ b/test/mocha.opts @@ -0,0 +1 @@ +--require ./test/support.js diff --git a/test/model.test.js b/test/model.test.js index e8875e0b..ab854be7 100644 --- a/test/model.test.js +++ b/test/model.test.js @@ -4,12 +4,16 @@ // License text available at https://opensource.org/licenses/MIT var async = require('async'); +var chai = require('chai'); +var describe = require('./util/describe'); var loopback = require('../'); var ACL = loopback.ACL; var defineModelTestsWithDataSource = require('./util/model-tests'); var PersistedModel = loopback.PersistedModel; +var sinonChai = require('sinon-chai'); -var describe = require('./util/describe'); +var expect = chai.expect; +chai.use(sinonChai); describe('Model / PersistedModel', function() { defineModelTestsWithDataSource({ diff --git a/test/support.js b/test/support.js index 01ee765f..315e22ce 100644 --- a/test/support.js +++ b/test/support.js @@ -12,7 +12,6 @@ expect = require('chai').expect; loopback = require('../'); memoryConnector = loopback.Memory; GeoPoint = loopback.GeoPoint; -app = null; TaskEmitter = require('strong-task-emitter'); request = require('supertest'); var RemoteObjects = require('strong-remoting'); @@ -21,10 +20,6 @@ var RemoteObjects = require('strong-remoting'); // for tests using the built-in User model loopback.User.settings.saltWorkFactor = 4; -beforeEach(function() { - this.app = app = loopback(); -}); - assertValidDataSource = function(dataSource) { // has methods assert.isFunc(dataSource, 'createModel');