Skip to content

Commit 586fd83

Browse files
fix: regression autoDetectChanges (#347)
Closes #346
1 parent 7119268 commit 586fd83

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

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

+11-5
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, {
@@ -183,6 +192,7 @@ export async function render<SutType, WrapperType = SutType>(
183192
result = doNavigate();
184193
}
185194

195+
detectChanges();
186196
return result ?? false;
187197
};
188198

@@ -234,10 +244,6 @@ export async function render<SutType, WrapperType = SutType>(
234244
fixture.componentInstance.ngOnChanges(changes);
235245
}
236246

237-
if (autoDetectChanges) {
238-
fixture.autoDetectChanges(true);
239-
}
240-
241247
detectChanges = () => {
242248
if (isAlive) {
243249
fixture.detectChanges();
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)