Skip to content

Commit cd38cad

Browse files
fix: invoke detectChanges after additionalSetup
1 parent 05ae42c commit cd38cad

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

libs/ngx-cva-test-suite/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "Standardise your custom UI form components with ControlValueAccessor Test Suite",
44
"author": "Dmitriy Stepanenko",
55
"license": "MIT",
6-
"version": "1.0.2",
6+
"version": "1.0.3",
77
"repository": {
88
"type": "git",
99
"url": "https://github.com/dmitry-stepanenko/ngx-cva-test-suite"

libs/ngx-cva-test-suite/src/lib/ngx-cva-test-suite.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,10 @@ export function runValueAccessorTests<T extends CVAComponentType, H = T>(config:
5757
beforeEach(() => {
5858
if (config.hostTemplate) {
5959
fixture = TestBed.createComponent(config.hostTemplate.hostComponent);
60-
fixture.detectChanges();
61-
componentInstance = config.hostTemplate.getTestingComponent(fixture);
6260
} else {
6361
// if there's no host template specified, component will be tested directly.
6462
// in this case fixture will be based on actual component
6563
fixture = TestBed.createComponent(config.component as any);
66-
fixture.detectChanges();
67-
componentInstance = fixture.componentInstance as any;
6864
}
6965
});
7066

@@ -75,8 +71,15 @@ export function runValueAccessorTests<T extends CVAComponentType, H = T>(config:
7571
}
7672

7773
beforeEach(() => {
74+
// defining componentInstance after "additionalSetup",
75+
// because "detectChanges()" should not be called before it
7876
fixture.detectChanges();
77+
componentInstance = config.hostTemplate
78+
? config.hostTemplate.getTestingComponent(fixture)
79+
: (fixture.componentInstance as any);
80+
});
7981

82+
beforeEach(() => {
8083
onChangeSpy = testRunnerResolver.createSpy();
8184
onTouchedSpy = testRunnerResolver.createSpy();
8285

0 commit comments

Comments
 (0)