-
-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(spectator): support for Function-based outputs (#671)
* feat(spectator): support for Function-based outputs * feat(spectator): limit the output keys at compile time to outputs only * fix(spectator): properly infer the type when passing a T argument for the output * chore(spectator): cleanup the output method overloads and used types --------- Co-authored-by: Anatolie Darii <[email protected]>
- Loading branch information
1 parent
defdedd
commit 02ed01d
Showing
4 changed files
with
118 additions
and
6 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
projects/spectator/jest/test/function-output/function-output.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,47 @@ | ||
import { createComponentFactory, createHostFactory, Spectator, SpectatorHost } from '@ngneat/spectator/jest'; | ||
import { FunctionOutputComponent } from '../../../test/function-output/function-output.component'; | ||
|
||
describe('FunctionOutputComponent', () => { | ||
describe('with Spectator', () => { | ||
let spectator: Spectator<FunctionOutputComponent>; | ||
|
||
const createComponent = createComponentFactory({ | ||
component: FunctionOutputComponent, | ||
}); | ||
|
||
beforeEach(() => { | ||
spectator = createComponent(); | ||
}); | ||
|
||
it('should emit the event on button click', () => { | ||
let output; | ||
spectator.output('buttonClick').subscribe((result) => (output = result)); | ||
|
||
spectator.click('button'); | ||
|
||
expect(output).toEqual(true); | ||
}); | ||
}); | ||
|
||
describe('with SpectatorHost', () => { | ||
let host: SpectatorHost<FunctionOutputComponent>; | ||
|
||
const createHost = createHostFactory({ | ||
component: FunctionOutputComponent, | ||
template: `<app-function-output/>`, | ||
}); | ||
|
||
beforeEach(() => { | ||
host = createHost(); | ||
}); | ||
|
||
it('should emit the event on button click', () => { | ||
let output; | ||
host.output('buttonClick').subscribe((result) => (output = result)); | ||
|
||
host.click('button'); | ||
|
||
expect(output).toEqual(true); | ||
}); | ||
}); | ||
}); |
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
47 changes: 47 additions & 0 deletions
47
projects/spectator/test/function-output/function-output.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,47 @@ | ||
import { createComponentFactory, createHostFactory, Spectator, SpectatorHost } from '@ngneat/spectator'; | ||
import { FunctionOutputComponent } from './function-output.component'; | ||
|
||
describe('FunctionOutputComponent', () => { | ||
describe('with Spectator', () => { | ||
let spectator: Spectator<FunctionOutputComponent>; | ||
|
||
const createComponent = createComponentFactory({ | ||
component: FunctionOutputComponent, | ||
}); | ||
|
||
beforeEach(() => { | ||
spectator = createComponent(); | ||
}); | ||
|
||
it('should emit the event on button click', () => { | ||
let output; | ||
spectator.output('buttonClick').subscribe((result) => (output = result)); | ||
|
||
spectator.click('button'); | ||
|
||
expect(output).toEqual(true); | ||
}); | ||
}); | ||
|
||
describe('with SpectatorHost', () => { | ||
let host: SpectatorHost<FunctionOutputComponent>; | ||
|
||
const createHost = createHostFactory({ | ||
component: FunctionOutputComponent, | ||
template: `<app-function-output/>`, | ||
}); | ||
|
||
beforeEach(() => { | ||
host = createHost(); | ||
}); | ||
|
||
it('should emit the event on button click', () => { | ||
let output; | ||
host.output('buttonClick').subscribe((result) => (output = result)); | ||
|
||
host.click('button'); | ||
|
||
expect(output).toEqual(true); | ||
}); | ||
}); | ||
}); |
10 changes: 10 additions & 0 deletions
10
projects/spectator/test/function-output/function-output.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,10 @@ | ||
import { Component, input, output, ɵINPUT_SIGNAL_BRAND_WRITE_TYPE } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'app-function-output', | ||
template: ` <button (click)="buttonClick.emit(true)">Emit function output</button> `, | ||
standalone: true, | ||
}) | ||
export class FunctionOutputComponent { | ||
public buttonClick = output<boolean>(); | ||
} |