Skip to content

Commit

Permalink
fix(mock-render): detectChanges flag has to be provided to supress re…
Browse files Browse the repository at this point in the history
…nder
  • Loading branch information
satanTime committed May 13, 2021
1 parent 9122663 commit 8195eeb
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
2 changes: 1 addition & 1 deletion libs/ng-mocks/src/lib/mock-render/mock-render.ts
Expand Up @@ -50,7 +50,7 @@ const fixtureFactory = <T>(template: any, meta: Directive, params: any, flags: a
template: mockTemplate,
};
const fixture: any = generateFixture({ ...meta, params, options });
if (flags.detectChanges) {
if (flags.detectChanges === undefined || flags.detectChanges) {
fixture.detectChanges();
}

Expand Down
63 changes: 63 additions & 0 deletions tests/ng-mocks-render/cdr.spec.ts
@@ -0,0 +1,63 @@
import { Component, OnInit } from '@angular/core';
import { MockBuilder, MockRender, ngMocks } from 'ng-mocks';

@Component({
selector: 'target',
template: '{{ value }}',
})
class TargetComponent implements OnInit {
public value = '';

public ngOnInit(): void {
this.value = 'rendered';
}
}

describe('ng-mocks-render:cdr', () => {
ngMocks.faster();
beforeAll(() => MockBuilder(TargetComponent));

it('detects instantly w/o params and options', () => {
const fixture = MockRender(TargetComponent);
expect(ngMocks.formatText(fixture)).toEqual('rendered');
});

it('detects instantly w/ params and w/o options', () => {
const fixture = MockRender(TargetComponent, {});
expect(ngMocks.formatText(fixture)).toEqual('rendered');
});

it('detects instantly w/ params and w/ options', () => {
const fixture = MockRender(TargetComponent, {}, {});
expect(ngMocks.formatText(fixture)).toEqual('rendered');
});

it('detects instantly w/ params and w/ flag', () => {
const fixture = MockRender(
TargetComponent,
{},
{
detectChanges: true,
},
);
expect(ngMocks.formatText(fixture)).toEqual('rendered');
});

it('does not detect as a flag', () => {
const fixture = MockRender(TargetComponent, undefined, false);
expect(ngMocks.formatText(fixture)).toEqual('');

fixture.detectChanges();
expect(ngMocks.formatText(fixture)).toEqual('rendered');
});

it('does not detect as options', () => {
const fixture = MockRender(TargetComponent, undefined, {
detectChanges: false,
});
expect(ngMocks.formatText(fixture)).toEqual('');

fixture.detectChanges();
expect(ngMocks.formatText(fixture)).toEqual('rendered');
});
});

0 comments on commit 8195eeb

Please sign in to comment.