2017-05-29 21:50:03 +03:00
|
|
|
import sinon from 'sinon';
|
2016-11-24 01:50:57 +03:00
|
|
|
import {describe, it} from 'mocha';
|
2017-05-29 21:50:03 +03:00
|
|
|
import {expect} from 'chai';
|
2016-11-24 01:50:57 +03:00
|
|
|
import {setupTest} from 'ember-mocha';
|
2016-08-17 18:01:46 +03:00
|
|
|
|
2018-01-05 18:38:23 +03:00
|
|
|
describe('Unit: Service: event-bus', function () {
|
2019-05-13 15:43:53 +03:00
|
|
|
setupTest();
|
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
it('works', function () {
|
2019-05-13 15:43:53 +03:00
|
|
|
let service = this.owner.lookup('service:event-bus');
|
2016-11-24 01:50:57 +03:00
|
|
|
let eventHandler = sinon.spy();
|
2016-08-17 18:01:46 +03:00
|
|
|
|
2019-07-22 15:16:00 +03:00
|
|
|
service.subscribe('test-event', this, 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
|
|
|
|
2019-07-22 15:16:00 +03:00
|
|
|
service.unsubscribe('test-event', this, 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;
|
|
|
|
});
|
|
|
|
});
|