ts-simple-ast
Version:
TypeScript compiler wrapper for AST navigation and code generation.
41 lines (39 loc) • 1.57 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const chai_1 = require("chai");
const utils_1 = require("./../../utils");
describe("EventContainer", () => {
it("should support subscribing", () => {
let firedCount = 0;
const container = new utils_1.EventContainer();
container.subscribe(() => firedCount++);
container.fire(undefined);
chai_1.expect(firedCount).to.equal(1);
});
it("should pass in the arg when firing", () => {
let capturedArg = "";
const container = new utils_1.EventContainer();
container.subscribe(arg => capturedArg = arg);
container.fire("test");
chai_1.expect(capturedArg).to.equal("test");
});
it("should only fire the subscription once if subscribed multiple times with the same subscription", () => {
let firedCount = 0;
const subscription = () => firedCount++;
const container = new utils_1.EventContainer();
container.subscribe(subscription);
container.subscribe(subscription);
container.fire(undefined);
chai_1.expect(firedCount).to.equal(1);
});
it("should support unsubscribing", () => {
let firedCount = 0;
const subscription = () => firedCount++;
const container = new utils_1.EventContainer();
container.subscribe(subscription);
container.unsubscribe(subscription);
container.fire(undefined);
chai_1.expect(firedCount).to.equal(0);
});
});
//# sourceMappingURL=eventContainerTests.js.map