Skip to content

Commit 580a0b6

Browse files
committed
saving
1 parent ef85d65 commit 580a0b6

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { it, vi, expect } from 'vitest';
2+
3+
import { EventEmitter } from './event_emitter';
4+
5+
it('should call all registered listeners on emit event', () => {
6+
const emitter = new EventEmitter<{ foo: number, bar: string }>();
7+
const fooListener1 = vi.fn();
8+
const fooListener2 = vi.fn();
9+
10+
emitter.on('foo', fooListener1);
11+
emitter.on('foo', fooListener2);
12+
13+
const barListener1 = vi.fn();
14+
const barListener2 = vi.fn();
15+
16+
emitter.on('bar', barListener1);
17+
emitter.on('bar', barListener2);
18+
19+
emitter.emit('foo', 1);
20+
expect(fooListener1).toHaveBeenCalledWith(1);
21+
expect(fooListener2).toHaveBeenCalledWith(1);
22+
})
23+
24+
// it('should remove listeners', () => {
25+
// const emitter = new EventEmitter();
26+
// const cb = jest.fn();
27+
// emitter.on('foo', cb);
28+
// emitter.off('foo', cb);
29+
// emitter.emit('foo');
30+
// expect(cb).not.toHaveBeenCalled();
31+
// })
32+
33+
// it('should remove all listeners', () => {
34+
// const emitter = new EventEmitter();
35+
// const cb = jest.fn();
36+
// emitter.on('foo', cb);
37+
// emitter.on('foo', cb);
38+
// emitter.off('foo');
39+
// emitter.emit('foo');
40+
// expect(cb).not.toHaveBeenCalled();
41+
// }

vitest.config.mts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ export default defineConfig({
44
test: {
55
onConsoleLog: () => true,
66
environment: 'happy-dom',
7-
include: ['**/*.spec.ts'],
7+
include: ['**/event_emitter.spec.ts'],
88
typecheck: {
99
tsconfig: 'tsconfig.spec.json',
10+
exclude: ['**/index.react_native.spec.ts'],
1011
},
1112
},
1213
});

0 commit comments

Comments
 (0)