Ghost/ghost/admin/tests/unit/services/event-bus-test.js

32 lines
844 B
JavaScript
Raw Normal View History

/* jshint expr:true */
import {expect} from 'chai';
2016-11-24 01:50:57 +03:00
import {describe, it} from 'mocha';
import {setupTest} from 'ember-mocha';
import sinon from 'sinon';
2016-11-24 01:50:57 +03:00
describe('Unit: Service: event-bus', function() {
setupTest('service:event-bus', {});
it('works', function () {
let service = this.subject();
let eventHandler = sinon.spy();
2016-11-24 01:50:57 +03:00
service.subscribe('test-event', eventHandler);
2016-11-24 01:50:57 +03:00
service.publish('test-event', 'test');
2016-11-24 01:50:57 +03:00
service.unsubscribe('test-event', eventHandler);
2016-11-24 01:50:57 +03:00
service.publish('test-event', 'test two');
2016-11-24 01:50:57 +03:00
expect(
eventHandler.calledOnce,
'event handler only triggered once'
).to.be.true;
2016-11-24 01:50:57 +03:00
expect(
eventHandler.calledWith('test'),
'event handler was passed correct arguments'
).to.be.true;
});
});