-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(mock-render): skipping proxy for bindings from factory #621
- Loading branch information
Showing
3 changed files
with
72 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { | ||
Component, | ||
EventEmitter, | ||
Input, | ||
Output, | ||
} from '@angular/core'; | ||
import { MockBuilder, MockRenderFactory, ngMocks } from 'ng-mocks'; | ||
|
||
@Component({ | ||
selector: 'target', | ||
template: `<button (click)="update.emit(value)"> | ||
{{ value }} | ||
</button>`, | ||
}) | ||
class TargetComponent { | ||
@Output() public readonly update = new EventEmitter< | ||
number | null | undefined | ||
>(); | ||
@Input() public readonly value: number | null | undefined = null; | ||
} | ||
|
||
describe('issue-621', () => { | ||
ngMocks.faster(); | ||
|
||
beforeAll(() => MockBuilder(TargetComponent)); | ||
|
||
let factory: MockRenderFactory<TargetComponent, 'update' | 'value'>; | ||
beforeAll( | ||
() => | ||
(factory = MockRenderFactory(TargetComponent, [ | ||
'update', | ||
'value', | ||
])), | ||
); | ||
|
||
it('does not proxy update inout', () => { | ||
const fixture = factory(); | ||
expect(fixture.componentInstance.value).toEqual(undefined); | ||
expect(fixture.point.componentInstance.value).toEqual(undefined); | ||
|
||
fixture.componentInstance.value = 1; | ||
expect(fixture.componentInstance.value).toEqual(1); | ||
expect(fixture.point.componentInstance.value).toEqual(undefined); | ||
}); | ||
|
||
it('does not proxy update inout', () => { | ||
const fixture = factory(); | ||
expect(fixture.componentInstance.update).toEqual(undefined); | ||
|
||
fixture.componentInstance.value = 5; | ||
// sets the value to point | ||
fixture.detectChanges(); | ||
|
||
// checking that the emitted value comes | ||
// back to the middleware component | ||
ngMocks.click('button'); | ||
expect(fixture.componentInstance.update).toEqual(5); | ||
}); | ||
}); |