-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
924eb00
commit 6e4b64f
Showing
13 changed files
with
212 additions
and
275 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,17 @@ | ||
import { EventEmitter } from "../src"; | ||
import EventEmitter from "../src"; | ||
|
||
it("returns the number of listeners for a given event", () => { | ||
const e = new EventEmitter(); | ||
|
||
expect(e.listenerCount("foo")).toBe(0); | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
e.on("foo", function() { | ||
}); | ||
e.on("foo", function () {}); | ||
|
||
expect(e.listenerCount("foo")).toBe(1); | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
e.on("foo", function() { | ||
}); | ||
e.on("foo", function () {}); | ||
|
||
expect(e.listenerCount("foo")).toBe(2); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,19 @@ | ||
import { EventEmitter } from "../src"; | ||
import EventEmitter from "../src"; | ||
|
||
it("throws an error if the listener is not a function", () => { | ||
it("should listen to all the emits", () => { | ||
const e = new EventEmitter(); | ||
let calls = 0; | ||
|
||
try { | ||
e.on("foo", "bar" as any); | ||
} catch (ex) { | ||
expect(ex).toBeInstanceOf(TypeError); | ||
expect(ex.message).toBe("'listener' must be a function"); | ||
return; | ||
} | ||
e.on("foo", () => { | ||
calls++; | ||
}); | ||
|
||
throw new Error("oops"); | ||
e.emit("foo"); | ||
e.emit("foo"); | ||
e.emit("foo"); | ||
e.emit("foo"); | ||
e.emit("foo"); | ||
|
||
expect(e.listeners("foo").length).toBe(1); | ||
expect(calls).toBe(5); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.