diff --git a/projects/testing-library/src/lib/testing-library.ts b/projects/testing-library/src/lib/testing-library.ts index 1b1428d..387ae10 100644 --- a/projects/testing-library/src/lib/testing-library.ts +++ b/projects/testing-library/src/lib/testing-library.ts @@ -66,7 +66,16 @@ export async function render( defaultImports = [], } = { ...globalConfig, ...renderOptions }; - dtlConfigure(domConfig); + dtlConfigure({ + eventWrapper: (cb) => { + const result = cb(); + if (autoDetectChanges) { + detectChangesForMountedFixtures(); + } + return result; + }, + ...domConfig, + }); TestBed.configureTestingModule({ declarations: addAutoDeclarations(sut, { @@ -183,6 +192,7 @@ export async function render( result = doNavigate(); } + detectChanges(); return result ?? false; }; @@ -234,10 +244,6 @@ export async function render( fixture.componentInstance.ngOnChanges(changes); } - if (autoDetectChanges) { - fixture.autoDetectChanges(true); - } - detectChanges = () => { if (isAlive) { fixture.detectChanges(); diff --git a/projects/testing-library/tests/issues/issue-346.spec.ts b/projects/testing-library/tests/issues/issue-346.spec.ts new file mode 100644 index 0000000..ef1b7a3 --- /dev/null +++ b/projects/testing-library/tests/issues/issue-346.spec.ts @@ -0,0 +1,17 @@ +import { Component } from '@angular/core'; +import { render } from '../../src/public_api'; + +test('issue 364 detectChangesOnRender', async () => { + @Component({ + selector: 'atl-fixture', + template: `{{ myObj.myProp }}`, + }) + class MyComponent { + myObj: any = null; + } + + // autoDetectChanges invokes change detection, which makes the test fail + await render(MyComponent, { + detectChangesOnRender: false, + }); +});