Skip to content

Commit 4b57993

Browse files
committed
added bubble unit tests
1 parent 08badba commit 4b57993

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/mixins/event.spec.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,32 @@ describe('The event mixin', () => {
144144
expect(updateFn).toHaveBeenCalledTimes(1);
145145
expect(errorFn).toHaveBeenCalledTimes(1);
146146
});
147+
148+
it('should bubble events', async () => {
149+
const cls0 = new TextClass();
150+
const cls1 = new TextClass();
151+
152+
cls0.bubble(cls1);
153+
154+
const frameFn0 = vi.fn();
155+
const frameFn1 = vi.fn();
156+
157+
cls0.on('update', frameFn0);
158+
cls1.on('update', frameFn1);
159+
160+
cls0.trigger('update', 2);
161+
162+
expect(frameFn0).toHaveBeenCalledTimes(1);
163+
expect(frameFn0.mock.calls[0][0].detail).toBe(2);
164+
165+
expect(frameFn1).toHaveBeenCalledTimes(1);
166+
expect(frameFn1.mock.calls[0][0].detail).toBe(2);
167+
168+
cls1.trigger('update', 3);
169+
170+
expect(frameFn0).toHaveBeenCalledTimes(1);
171+
expect(frameFn1).toHaveBeenCalledTimes(2);
172+
});
147173
});
148174

149175
type Events = {

src/mixins/event.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export function EventEmitterMixin<Events = {}, T extends Constructor = Construct
6666

6767
public bubble(target: EventEmitter) {
6868
return this.on('*', (event: EmittedEvent<any, any>) => {
69-
target.trigger(event.type as any, event.target);
69+
target.trigger(event.type as any, event.detail);
7070
});
7171
}
7272

0 commit comments

Comments
 (0)