]>
git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/linter/safe-emitter.js
2 * @fileoverview Tests for safe-emitter
8 const createEmitter
= require("../../../lib/linter/safe-emitter");
9 const assert
= require("chai").assert
;
11 describe("safe-emitter", () => {
12 describe("emit() and on()", () => {
13 it("allows listeners to be registered calls them when emitted", () => {
14 const emitter
= createEmitter();
17 emitter
.on("foo", () => colors
.push("red"));
18 emitter
.on("foo", () => colors
.push("blue"));
19 emitter
.on("bar", () => colors
.push("green"));
22 assert
.deepStrictEqual(colors
, ["red", "blue"]);
24 emitter
.on("bar", color
=> colors
.push(color
));
25 emitter
.emit("bar", "yellow");
27 assert
.deepStrictEqual(colors
, ["red", "blue", "green", "yellow"]);
30 it("calls listeners with no `this` value", () => {
31 const emitter
= createEmitter();
34 emitter
.on("foo", function() {
35 assert
.strictEqual(this, void 0); // eslint-disable-line no-invalid-this