diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-type-bind-relation.service.spec.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-type-bind-relation.service.spec.ts index 7311d19e949..9faec7dd7d4 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-type-bind-relation.service.spec.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-type-bind-relation.service.spec.ts @@ -26,7 +26,10 @@ describe('DSDynamicTypeBindRelationService test suite', () => { let injector: Injector; beforeEach(() => { - TestBed.configureTestingModule({ + // Return the promise so the module (and its fresh getMockFormBuilderService() spy mock) is fully set up + // before each spec runs; the previous dangling .then() did not await, letting asynchronous module setup + // leak between specs. + return TestBed.configureTestingModule({ imports: [ReactiveFormsModule], providers: [ { provide: FormBuilderService, useValue: getMockFormBuilderService() }, @@ -34,7 +37,7 @@ describe('DSDynamicTypeBindRelationService test suite', () => { { provide: DynamicFormRelationService }, DISABLED_MATCHER_PROVIDER, HIDDEN_MATCHER_PROVIDER, REQUIRED_MATCHER_PROVIDER ] - }).compileComponents().then(); + }).compileComponents(); }); beforeEach(inject([DsDynamicTypeBindRelationService, DynamicFormRelationService], @@ -86,7 +89,7 @@ describe('DSDynamicTypeBindRelationService test suite', () => { it('Should not push undefined bind models', () => { const testModel = mockInputWithTypeBindModel; testModel.typeBindRelations = getTypeBindRelations(['boundType']); - spyOn((service as any).formBuilderService, 'getTypeBindModel').and.returnValue(undefined); + ((service as any).formBuilderService.getTypeBindModel as jasmine.Spy).and.returnValue(undefined); const relatedModels = service.getRelatedFormModel(testModel); @@ -143,7 +146,7 @@ describe('DSDynamicTypeBindRelationService test suite', () => { opposingMatch: HIDDEN_MATCHER.match, onChange: jasmine.createSpy('onChange') }; - spyOn((service as any).formBuilderService, 'getTypeBindModel').and.returnValue(undefined); + ((service as any).formBuilderService.getTypeBindModel as jasmine.Spy).and.returnValue(undefined); const hasMatch = service.matchesCondition(relation, visibleMatcher); @@ -159,7 +162,7 @@ describe('DSDynamicTypeBindRelationService test suite', () => { opposingMatch: MATCH_VISIBLE, onChange: jasmine.createSpy('onChange') }; - spyOn((service as any).formBuilderService, 'getTypeBindModel').and.returnValue(undefined); + ((service as any).formBuilderService.getTypeBindModel as jasmine.Spy).and.returnValue(undefined); const hasMatch = service.matchesCondition(relation, hiddenMatcher); @@ -185,8 +188,8 @@ describe('DSDynamicTypeBindRelationService test suite', () => { onChange: jasmine.createSpy('onChange') }; (service as any).dynamicMatchers = [visibleMatcher]; - spyOn((service as any).formBuilderService, 'getTypeBindModel').and.callFake(() => bindModelAvailable ? bindModel : undefined); - spyOn((service as any).formBuilderService, 'getTypeBindModelUpdates').and.returnValue(bindModelUpdates$.asObservable()); + ((service as any).formBuilderService.getTypeBindModel as jasmine.Spy).and.callFake(() => bindModelAvailable ? bindModel : undefined); + ((service as any).formBuilderService.getTypeBindModelUpdates as jasmine.Spy).and.returnValue(bindModelUpdates$.asObservable()); const subscriptions = service.subscribeRelations(testModel, dcTypeControl); expect(subscriptions.length).toBe(1); @@ -220,8 +223,8 @@ describe('DSDynamicTypeBindRelationService test suite', () => { onChange: jasmine.createSpy('onChange') }; (service as any).dynamicMatchers = [hiddenMatcher]; - spyOn((service as any).formBuilderService, 'getTypeBindModel').and.callFake(() => bindModelAvailable ? bindModel : undefined); - spyOn((service as any).formBuilderService, 'getTypeBindModelUpdates').and.returnValue(bindModelUpdates$.asObservable()); + ((service as any).formBuilderService.getTypeBindModel as jasmine.Spy).and.callFake(() => bindModelAvailable ? bindModel : undefined); + ((service as any).formBuilderService.getTypeBindModelUpdates as jasmine.Spy).and.returnValue(bindModelUpdates$.asObservable()); const subscriptions = service.subscribeRelations(testModel, dcTypeControl); expect(subscriptions.length).toBe(1); @@ -254,8 +257,8 @@ describe('DSDynamicTypeBindRelationService test suite', () => { onChange: jasmine.createSpy('onChange') }; (service as any).dynamicMatchers = [visibleMatcher]; - spyOn((service as any).formBuilderService, 'getTypeBindModel').and.callFake(() => bindModelAvailable ? bindModel : undefined); - spyOn((service as any).formBuilderService, 'getTypeBindModelUpdates').and.returnValue(bindModelUpdates$.asObservable()); + ((service as any).formBuilderService.getTypeBindModel as jasmine.Spy).and.callFake(() => bindModelAvailable ? bindModel : undefined); + ((service as any).formBuilderService.getTypeBindModelUpdates as jasmine.Spy).and.returnValue(bindModelUpdates$.asObservable()); const subscriptions = service.subscribeRelations(testModel, dcTypeControl); expect(visibleMatcher.onChange).toHaveBeenCalledWith(false, testModel, dcTypeControl, jasmine.anything());