mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2025-12-18 13:43:27 +00:00
* Tgui: Events & Colors in typescript (#83218) ## About The Pull Request Made more common tgui bits in typescript with tests. Not much else to see here ## Why It's Good For The Game Typescript conversion + More documentation + type safety You now get full docs and type info as nature intended:  --------- Co-authored-by: Style Mistake <stylemistake@ gmail.com> * Tgui: Events & Colors in typescript --------- Co-authored-by: Jeremiah <42397676+jlsnow301@users.noreply.github.com> Co-authored-by: Style Mistake <stylemistake@ gmail.com>
35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import { EventEmitter } from './events';
|
|
|
|
describe('EventEmitter', () => {
|
|
it('should add and trigger an event listener', () => {
|
|
const emitter = new EventEmitter();
|
|
const mockListener = jest.fn();
|
|
emitter.on('test', mockListener);
|
|
emitter.emit('test', 'payload');
|
|
expect(mockListener).toHaveBeenCalledWith('payload');
|
|
});
|
|
|
|
it('should remove an event listener', () => {
|
|
const emitter = new EventEmitter();
|
|
const mockListener = jest.fn();
|
|
emitter.on('test', mockListener);
|
|
emitter.off('test', mockListener);
|
|
emitter.emit('test', 'payload');
|
|
expect(mockListener).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('should not fail when emitting an event with no listeners', () => {
|
|
const emitter = new EventEmitter();
|
|
expect(() => emitter.emit('test', 'payload')).not.toThrow();
|
|
});
|
|
|
|
it('should clear all event listeners', () => {
|
|
const emitter = new EventEmitter();
|
|
const mockListener = jest.fn();
|
|
emitter.on('test', mockListener);
|
|
emitter.clear();
|
|
emitter.emit('test', 'payload');
|
|
expect(mockListener).not.toHaveBeenCalled();
|
|
});
|
|
});
|