fix: model_events_spec.js just throws a general event for "everyone"

This commit is contained in:
kirrg001 2016-06-09 15:36:50 +02:00
parent bdef04bcda
commit 37317db031

View File

@ -1,6 +1,7 @@
/*globals describe, before, afterEach, it*/
var should = require('should'),
sinon = require('sinon'),
rewire = require('rewire'),
sandbox = sinon.sandbox.create(),
events = require('../../server/events'),
Models = require('../../server/models');
@ -9,7 +10,15 @@ var should = require('should'),
should.equal(true, true);
describe('Model Events', function () {
var eventsToRemember = {};
before(function () {
sandbox.stub(events, 'on', function (name, callback) {
eventsToRemember[name] = callback;
});
rewire('../../server/models/base/events');
// Loads all the models
Models.init();
});
@ -22,8 +31,10 @@ describe('Model Events', function () {
it('calls User edit when event is emitted', function (done) {
// Setup
var userModelSpy = sandbox.spy(Models.User, 'edit');
// Test
events.emit('token.added', {get: function () { return 1; }});
eventsToRemember['token.added']({get: function () { return 1; }});
// Assert
userModelSpy.calledOnce.should.be.true();
userModelSpy.calledWith(