Skip to content

Commit

Permalink
Merge pull request #542 from /issues/537
Browse files Browse the repository at this point in the history
test: covering ChangeDetectionStrategy.OnPush #537
  • Loading branch information
satanTime authored May 12, 2021
2 parents 6e08b34 + 6b07067 commit 8870d21
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions tests/issue-537/test.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import {
ChangeDetectionStrategy,
Component,
EventEmitter,
Output,
} from '@angular/core';
import { MockBuilder, MockRender, ngMocks } from 'ng-mocks';

@Component({
changeDetection: ChangeDetectionStrategy.OnPush,
selector: 'target',
template: '{{ value }}',
})
class TargetComponent {
@Output() public readonly update = new EventEmitter<void>();
public value = 0;

public triggerUpdate(): void {
this.value += 1;
this.update.emit();
}
}

describe('issue-537', () => {
ngMocks.faster();
beforeAll(() => MockBuilder(TargetComponent));

it('renders default value w/o subscribers', () => {
const fixture = MockRender(TargetComponent);
expect(ngMocks.formatText(fixture)).toEqual('0');
fixture.point.componentInstance.triggerUpdate();
fixture.detectChanges();
expect(ngMocks.formatText(fixture)).toEqual('0');
});

it('renders changed value w/ subscribers', () => {
const fixture = MockRender(TargetComponent, {
update: undefined,
});
expect(ngMocks.formatText(fixture)).toEqual('0');
fixture.point.componentInstance.triggerUpdate();
fixture.detectChanges();
expect(ngMocks.formatText(fixture)).toEqual('1');
});
});

0 comments on commit 8870d21

Please sign in to comment.