mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-01-09 00:17:59 +08:00
25 lines
715 B
JavaScript
25 lines
715 B
JavaScript
import Emitter from "../../js/lib/emitter";
|
|
|
|
test("listener callbacks are called on dispatch", () => {
|
|
const emitter = new Emitter();
|
|
const callback1 = jest.fn();
|
|
const callback2 = jest.fn();
|
|
|
|
emitter.addListener(callback1);
|
|
emitter.addListener(callback2);
|
|
emitter.dispatch({ data: 1 });
|
|
|
|
expect(callback1).toHaveBeenCalledWith({ data: 1 });
|
|
expect(callback2).toHaveBeenCalledWith({ data: 1 });
|
|
});
|
|
|
|
test("addListener returns a subscription object that can be destroyed", () => {
|
|
const emitter = new Emitter();
|
|
const callback1 = jest.fn();
|
|
|
|
const subscription = emitter.addListener(callback1);
|
|
subscription.destroy();
|
|
emitter.dispatch({});
|
|
|
|
expect(callback1).not.toHaveBeenCalled();
|
|
});
|