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

32 lines
836 B
JavaScript
Raw Normal View History

import sinon from 'sinon';
2016-11-24 01:50:57 +03:00
import {describe, it} from 'mocha';
import {expect} from 'chai';
2016-11-24 01:50:57 +03:00
import {setupTest} from 'ember-mocha';
describe('Unit: Service: event-bus', function () {
setupTest();
2016-11-24 01:50:57 +03:00
it('works', function () {
let service = this.owner.lookup('service:event-bus');
2016-11-24 01:50:57 +03:00
let eventHandler = sinon.spy();
service.subscribe('test-event', this, eventHandler);
2016-11-24 01:50:57 +03:00
service.publish('test-event', 'test');
service.unsubscribe('test-event', this, 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;
});
});