-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ngMocks.stubMember): forwarding stub values to point.componentIns…
…tance #1165
- Loading branch information
Showing
3 changed files
with
72 additions
and
6 deletions.
There are no files selected for viewing
17 changes: 15 additions & 2 deletions
17
libs/ng-mocks/src/lib/mock-helper/mock-helper.stub-member.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
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,44 @@ | ||
import { Component } from '@angular/core'; | ||
import { MockBuilder, MockRender, ngMocks } from 'ng-mocks'; | ||
|
||
@Component({ | ||
selector: 'target', | ||
template: `{{ value }}`, | ||
}) | ||
class TargetComponent { | ||
private valueOrigin = 0; | ||
|
||
public get value(): number { | ||
return this.valueOrigin; | ||
} | ||
|
||
public set value(value: number) { | ||
this.valueOrigin = value; | ||
} | ||
} | ||
|
||
// @see https://github.com/ike18t/ng-mocks/issues/1165 | ||
describe('issue-1165', () => { | ||
beforeEach(() => MockBuilder(TargetComponent)); | ||
|
||
it('sets values via proxy', () => { | ||
const fixture = MockRender(TargetComponent); | ||
expect(ngMocks.formatText(fixture)).toEqual('0'); | ||
|
||
fixture.componentInstance.value = 1; | ||
fixture.detectChanges(); | ||
expect(ngMocks.formatText(fixture)).toEqual('1'); | ||
|
||
fixture.point.componentInstance.value = 2; | ||
fixture.detectChanges(); | ||
expect(ngMocks.formatText(fixture)).toEqual('2'); | ||
|
||
ngMocks.stubMember(fixture.componentInstance, 'value', 3); | ||
fixture.detectChanges(); | ||
expect(ngMocks.formatText(fixture)).toEqual('3'); | ||
|
||
ngMocks.stubMember(fixture.point.componentInstance, 'value', 4); | ||
fixture.detectChanges(); | ||
expect(ngMocks.formatText(fixture)).toEqual('4'); | ||
}); | ||
}); |