forked from ngneat/spectator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 🎸 Add triggerEventHandler method (ngneat#249)
- Loading branch information
Showing
7 changed files
with
97 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
projects/spectator/test/child-custom-event/child-custom-event-parent.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Spectator, createComponentFactory } from '@ngneat/spectator'; | ||
|
||
import { ChildCustomEventParentComponent } from './child-custom-event-parent.component'; | ||
import { ChildCustomEventModule } from './child-custom-event.module'; | ||
import { ChildCustomEventComponent } from './child-custom-event.component'; | ||
import { byText } from '@ngneat/spectator'; | ||
|
||
describe('ChildCustomEventParentComponent', () => { | ||
let spectator: Spectator<ChildCustomEventParentComponent>; | ||
const createComponent = createComponentFactory({ | ||
component: ChildCustomEventParentComponent, | ||
imports: [ChildCustomEventModule], | ||
declareComponent: false | ||
}); | ||
|
||
it('should trigger custom event with directive selector', () => { | ||
spectator = createComponent(); | ||
spectator.triggerEventHandler(ChildCustomEventComponent, 'customEvent', 'hello'); | ||
expect(spectator.query(byText('hello'))).toExist(); | ||
}); | ||
|
||
it('should trigger custom event with string selector', () => { | ||
spectator = createComponent(); | ||
spectator.triggerEventHandler('app-child-custom-event', 'customEvent', 'hello'); | ||
expect(spectator.query(byText('hello'))).toExist(); | ||
}); | ||
}); |
16 changes: 16 additions & 0 deletions
16
projects/spectator/test/child-custom-event/child-custom-event-parent.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Component } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'app-child-custom-event-parent', | ||
template: ` | ||
<app-child-custom-event (customEvent)="onCustomEvent($event)"></app-child-custom-event> | ||
<p>{{ eventValue }}</p> | ||
` | ||
}) | ||
export class ChildCustomEventParentComponent { | ||
public eventValue = ''; | ||
|
||
public onCustomEvent(eventValue: string): void { | ||
this.eventValue = eventValue; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
projects/spectator/test/child-custom-event/child-custom-event.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Component, Output, EventEmitter } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'app-child-custom-event', | ||
template: ` | ||
<p>Custom child</p> | ||
` | ||
}) | ||
export class ChildCustomEventComponent { | ||
@Output() customEvent = new EventEmitter<string>(); | ||
} |
12 changes: 12 additions & 0 deletions
12
projects/spectator/test/child-custom-event/child-custom-event.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { CommonModule } from '@angular/common'; | ||
|
||
import { ChildCustomEventParentComponent } from './child-custom-event-parent.component'; | ||
import { ChildCustomEventComponent } from './child-custom-event.component'; | ||
|
||
@NgModule({ | ||
imports: [CommonModule], | ||
declarations: [ChildCustomEventParentComponent, ChildCustomEventComponent], | ||
exports: [ChildCustomEventParentComponent] | ||
}) | ||
export class ChildCustomEventModule {} |