2016-08-17 18:01:46 +03:00
|
|
|
/* jshint expr:true */
|
2016-11-14 16:16:51 +03:00
|
|
|
import {expect} from 'chai';
|
2016-11-24 01:50:57 +03:00
|
|
|
import {describe, it} from 'mocha';
|
|
|
|
import {setupTest} from 'ember-mocha';
|
2016-08-17 18:01:46 +03:00
|
|
|
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-08-17 18:01:46 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
service.subscribe('test-event', eventHandler);
|
2016-08-17 18:01:46 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
service.publish('test-event', 'test');
|
2016-08-17 18:01:46 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
service.unsubscribe('test-event', eventHandler);
|
2016-08-17 18:01:46 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
service.publish('test-event', 'test two');
|
2016-08-17 18:01:46 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
expect(
|
|
|
|
eventHandler.calledOnce,
|
|
|
|
'event handler only triggered once'
|
|
|
|
).to.be.true;
|
2016-08-17 18:01:46 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
expect(
|
|
|
|
eventHandler.calledWith('test'),
|
|
|
|
'event handler was passed correct arguments'
|
|
|
|
).to.be.true;
|
|
|
|
});
|
|
|
|
});
|