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

32 lines
824 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();
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;
});
});