Skip to content

Commit

Permalink
fix: invoke detectChanges after additionalSetup
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry-stepanenko committed Oct 19, 2021
1 parent 05ae42c commit cd38cad
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion libs/ngx-cva-test-suite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Standardise your custom UI form components with ControlValueAccessor Test Suite",
"author": "Dmitriy Stepanenko",
"license": "MIT",
"version": "1.0.2",
"version": "1.0.3",
"repository": {
"type": "git",
"url": "https://github.com/dmitry-stepanenko/ngx-cva-test-suite"
Expand Down
11 changes: 7 additions & 4 deletions libs/ngx-cva-test-suite/src/lib/ngx-cva-test-suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,10 @@ export function runValueAccessorTests<T extends CVAComponentType, H = T>(config:
beforeEach(() => {
if (config.hostTemplate) {
fixture = TestBed.createComponent(config.hostTemplate.hostComponent);
fixture.detectChanges();
componentInstance = config.hostTemplate.getTestingComponent(fixture);
} else {
// if there's no host template specified, component will be tested directly.
// in this case fixture will be based on actual component
fixture = TestBed.createComponent(config.component as any);
fixture.detectChanges();
componentInstance = fixture.componentInstance as any;
}
});

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

beforeEach(() => {
// defining componentInstance after "additionalSetup",
// because "detectChanges()" should not be called before it
fixture.detectChanges();
componentInstance = config.hostTemplate
? config.hostTemplate.getTestingComponent(fixture)
: (fixture.componentInstance as any);
});

beforeEach(() => {
onChangeSpy = testRunnerResolver.createSpy();
onTouchedSpy = testRunnerResolver.createSpy();

Expand Down

0 comments on commit cd38cad

Please sign in to comment.