|
1 | 1 | // Note: we need to import logger from the root
|
2 | 2 | // because this is the logger used in logError in ../src/common/util
|
3 | 3 | import { logger } from "../node_modules/@coder/logger"
|
| 4 | + |
4 | 5 | import { Emitter } from "../src/common/emitter"
|
5 | 6 |
|
6 |
| -describe("Emitter", () => { |
| 7 | +describe("emitter", () => { |
7 | 8 | let spy: jest.SpyInstance
|
8 | 9 |
|
9 | 10 | beforeEach(() => {
|
@@ -59,6 +60,25 @@ describe("Emitter", () => {
|
59 | 60 | emitter.dispose()
|
60 | 61 | })
|
61 | 62 |
|
| 63 | + it("should log an error if something goes wrong", async () => { |
| 64 | + const HELLO_WORLD = "HELLO_WORLD" |
| 65 | + const mockCallback = jest.fn(() => "Mock function called") |
| 66 | + const message = "You don't have access to that folder." |
| 67 | + |
| 68 | + const emitter = new Emitter<{ event: string; callback: () => void }>() |
| 69 | + |
| 70 | + const onHelloWorld = ({ event, callback }: { event: string; callback: () => void }): void => { |
| 71 | + if (event === HELLO_WORLD) { |
| 72 | + callback() |
| 73 | + throw new Error(message) |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + emitter.event(onHelloWorld) |
| 78 | + |
| 79 | + await emitter.emit({ event: HELLO_WORLD, callback: mockCallback }) |
| 80 | + }) |
| 81 | + |
62 | 82 | it("should log an error if something goes wrong", async () => {
|
63 | 83 | const HELLO_WORLD = "HELLO_WORLD"
|
64 | 84 | const mockCallback = jest.fn(() => "Mock function called")
|
|
0 commit comments