Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ build/Release
node_modules

# WebStorm
.idea
.idea

# NYC coverage output
.nyc_output
coverage
45 changes: 45 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -635,4 +635,49 @@ describe('AppBus', function () {
});
});

describe('Additional Coverage', function () {
it('rejects invalid event names', function () {
const bus = AppBusFactory.new();
expect(() => bus.publish(123)).to.throw('eventName');
});

it('rejects invalid subscribers', function () {
const bus = AppBusFactory.new();
expect(() => bus.subscribe('notFn')).to.throw('Function');
});

it('supports async publishing without payload', function (done) {
const bus = AppBusFactory.new();
let called = false;
bus.subscribe(() => { called = true; }).to('A');
bus.publish('A').async();
expect(called).to.equal(false);
setTimeout(() => {
expect(called).to.equal(true);
done();
}, 5);
});

it('clears all subscriptions via unsubscribeAll', function () {
const bus = AppBusFactory.new();
const fn = () => {};
bus.subscribe(fn).to('E');
expect(bus.getSubscriptions('E').length).to.equal(1);
bus.unsubscribeAll();
expect(bus.getSubscriptions('E').length).to.equal(0);
});

it('returns subscription list per event', function () {
const bus = AppBusFactory.new();
const fn1 = () => {};
const fn2 = () => {};
bus.subscribe(fn1).to('E1');
bus.subscribe(fn2).to('E2');
const subsE1 = bus.getSubscriptions('E1');
const allSubs = bus.getSubscriptions();
expect(subsE1[0].subscriber).to.equal(fn1);
expect(allSubs.length).to.equal(2);
});
});

});