Skip to content

Commit f6e672b

Browse files
committed
fix: fix: regression autoDetectChanges
1 parent 7119268 commit f6e672b

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

projects/testing-library/src/lib/testing-library.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,16 @@ export async function render<SutType, WrapperType = SutType>(
6666
defaultImports = [],
6767
} = { ...globalConfig, ...renderOptions };
6868

69-
dtlConfigure(domConfig);
69+
dtlConfigure({
70+
eventWrapper: (cb) => {
71+
const result = cb();
72+
if (autoDetectChanges) {
73+
detectChangesForMountedFixtures();
74+
}
75+
return result;
76+
},
77+
...domConfig,
78+
});
7079

7180
TestBed.configureTestingModule({
7281
declarations: addAutoDeclarations(sut, {
@@ -234,10 +243,6 @@ export async function render<SutType, WrapperType = SutType>(
234243
fixture.componentInstance.ngOnChanges(changes);
235244
}
236245

237-
if (autoDetectChanges) {
238-
fixture.autoDetectChanges(true);
239-
}
240-
241246
detectChanges = () => {
242247
if (isAlive) {
243248
fixture.detectChanges();
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Component } from '@angular/core';
2+
import { render } from '../../src/public_api';
3+
4+
test('issue 364 detectChangesOnRender', async () => {
5+
@Component({
6+
selector: 'atl-fixture',
7+
template: `{{ myObj.myProp }}`,
8+
})
9+
class MyComponent {
10+
myObj: any = null;
11+
}
12+
13+
// autoDetectChanges invokes change detection, which makes the test fail
14+
await render(MyComponent, {
15+
detectChangesOnRender: false,
16+
});
17+
});

0 commit comments

Comments
 (0)