Skip to content

Commit 3666963

Browse files
committed
feat(components): test EventEmitter by triggering event
1 parent dbb2397 commit 3666963

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/app/components/output.component.spec.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Component, Output, EventEmitter } from '@angular/core';
77

88
@Component({
99
selector: 'test',
10-
template: `<button (click)="greet.emit('Hi Juri')">Do greet</button>`
10+
template: `<button (click)="doGreet()">Do greet</button>`
1111
})
1212
export class OutputComponent {
1313
@Output() greet: EventEmitter<string> = new EventEmitter<string>();
@@ -44,7 +44,7 @@ describe('OutputComponent', () => {
4444
const button = fixture.nativeElement.querySelector('button');
4545
button.click();
4646

47-
expect(component.greet.emit).toHaveBeenCalledWith('Hi Juri');
47+
expect(component.greet.emit).toHaveBeenCalledWith('Hi');
4848
});
4949

5050
it('should test the emitter with a simple subscribe', async(() => {
@@ -53,7 +53,14 @@ describe('OutputComponent', () => {
5353
});
5454

5555
component.doGreet();
56+
}));
57+
58+
it('should fire the event emitter when triggering an event', async(() => {
59+
component.greet.subscribe((d) => {
60+
expect(d).toBe('Hi');
61+
});
5662

63+
fixture.debugElement.triggerEventHandler('greet', <Event>{});
5764
}));
5865

5966
});

0 commit comments

Comments
 (0)