require(
"@fatso83/mini-mocha"
).install();
const sinon = require(
"sinon"
);
const PubSub = require(
"pubsub-js"
);
const referee = require(
"@sinonjs/referee"
);
const assert = referee.assert;
describe(
"PubSub"
,
function
() {
it(
"Calling all the subscribers,
irrespective of exceptions."
,
function
() {
const message =
"an example message"
;
const stub = sinon.stub().throws();
const spy1 = sinon.spy();
const spy2 = sinon.spy();
const clock = sinon.useFakeTimers();
PubSub.subscribe(message, stub);
PubSub.subscribe(message, spy1);
PubSub.subscribe(message, spy2);
assert.exception(()=>{
PubSub.publishSync(message,
"some data"
);
clock.tick(1);
});
assert.exception(stub);
assert(spy1.called);
assert(spy2.called);
assert(stub.calledBefore(spy1));
clock.restore();
});
});