-
-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): ignoring host bindings in mocks #1427
- Loading branch information
Showing
5 changed files
with
107 additions
and
47 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
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,31 @@ | ||
import { Component, HostBinding, HostListener } from '@angular/core'; | ||
import { MockBuilder, MockRender, ngMocks } from 'ng-mocks'; | ||
|
||
@Component({ | ||
selector: 'target', | ||
template: '{{ id }}', | ||
}) | ||
export class TargetComponent { | ||
@HostBinding() public id = `custom-form`; | ||
@HostListener('click') public click = () => undefined; | ||
} | ||
|
||
describe('issue-1427', () => { | ||
beforeEach(() => MockBuilder(null, TargetComponent)); | ||
|
||
it('ignores host bindings in mock declarations', () => { | ||
const fixture = MockRender(TargetComponent); | ||
|
||
// HostBinding with id doesn't cause a side effect. | ||
expect(ngMocks.formatHtml(fixture)).toEqual('<target></target>'); | ||
|
||
// HostListener doesn't cause a side effect. | ||
expect( | ||
fixture.point.componentInstance.click, | ||
).not.toHaveBeenCalled(); | ||
ngMocks.trigger(fixture.point, 'click'); | ||
expect( | ||
fixture.point.componentInstance.click, | ||
).not.toHaveBeenCalled(); | ||
}); | ||
}); |