Skip to content

Commit b924ae5

Browse files
milanmajchrakclaude
andcommitted
test: fix flaky DSDynamicTypeBindRelationService spec (double spyOn)
The FormBuilderService mock (getMockFormBuilderService) is a jasmine.createSpyObj, so getTypeBindModel / getTypeBindModelUpdates are already spies. Several specs then call spyOn(...) on them again, which Jasmine rejects with "<spyOn> : getTypeBindModel has already been spied upon". Under Karma/Jasmine's randomized spec order this surfaced intermittently, so the same commit passed some CI runs and failed others. Reconfigure the existing spies via (spy as jasmine.Spy).and.returnValue/callFake(...) instead of re-spying them (the standard idiom for a createSpyObj mock). The spy behaviour per test is identical, so all assertions are unchanged; the illegal double-spyOn is removed, making "already been spied upon" impossible in any order. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent fecfa07 commit b924ae5

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-type-bind-relation.service.spec.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ describe('DSDynamicTypeBindRelationService test suite', () => {
8686
it('Should not push undefined bind models', () => {
8787
const testModel = mockInputWithTypeBindModel;
8888
testModel.typeBindRelations = getTypeBindRelations(['boundType']);
89-
spyOn((service as any).formBuilderService, 'getTypeBindModel').and.returnValue(undefined);
89+
((service as any).formBuilderService.getTypeBindModel as jasmine.Spy).and.returnValue(undefined);
9090

9191
const relatedModels = service.getRelatedFormModel(testModel);
9292

@@ -143,7 +143,7 @@ describe('DSDynamicTypeBindRelationService test suite', () => {
143143
opposingMatch: HIDDEN_MATCHER.match,
144144
onChange: jasmine.createSpy('onChange')
145145
};
146-
spyOn((service as any).formBuilderService, 'getTypeBindModel').and.returnValue(undefined);
146+
((service as any).formBuilderService.getTypeBindModel as jasmine.Spy).and.returnValue(undefined);
147147

148148
const hasMatch = service.matchesCondition(relation, visibleMatcher);
149149

@@ -159,7 +159,7 @@ describe('DSDynamicTypeBindRelationService test suite', () => {
159159
opposingMatch: MATCH_VISIBLE,
160160
onChange: jasmine.createSpy('onChange')
161161
};
162-
spyOn((service as any).formBuilderService, 'getTypeBindModel').and.returnValue(undefined);
162+
((service as any).formBuilderService.getTypeBindModel as jasmine.Spy).and.returnValue(undefined);
163163

164164
const hasMatch = service.matchesCondition(relation, hiddenMatcher);
165165

@@ -185,8 +185,8 @@ describe('DSDynamicTypeBindRelationService test suite', () => {
185185
onChange: jasmine.createSpy('onChange')
186186
};
187187
(service as any).dynamicMatchers = [visibleMatcher];
188-
spyOn((service as any).formBuilderService, 'getTypeBindModel').and.callFake(() => bindModelAvailable ? bindModel : undefined);
189-
spyOn((service as any).formBuilderService, 'getTypeBindModelUpdates').and.returnValue(bindModelUpdates$.asObservable());
188+
((service as any).formBuilderService.getTypeBindModel as jasmine.Spy).and.callFake(() => bindModelAvailable ? bindModel : undefined);
189+
((service as any).formBuilderService.getTypeBindModelUpdates as jasmine.Spy).and.returnValue(bindModelUpdates$.asObservable());
190190

191191
const subscriptions = service.subscribeRelations(testModel, dcTypeControl);
192192
expect(subscriptions.length).toBe(1);
@@ -220,8 +220,8 @@ describe('DSDynamicTypeBindRelationService test suite', () => {
220220
onChange: jasmine.createSpy('onChange')
221221
};
222222
(service as any).dynamicMatchers = [hiddenMatcher];
223-
spyOn((service as any).formBuilderService, 'getTypeBindModel').and.callFake(() => bindModelAvailable ? bindModel : undefined);
224-
spyOn((service as any).formBuilderService, 'getTypeBindModelUpdates').and.returnValue(bindModelUpdates$.asObservable());
223+
((service as any).formBuilderService.getTypeBindModel as jasmine.Spy).and.callFake(() => bindModelAvailable ? bindModel : undefined);
224+
((service as any).formBuilderService.getTypeBindModelUpdates as jasmine.Spy).and.returnValue(bindModelUpdates$.asObservable());
225225

226226
const subscriptions = service.subscribeRelations(testModel, dcTypeControl);
227227
expect(subscriptions.length).toBe(1);
@@ -254,8 +254,8 @@ describe('DSDynamicTypeBindRelationService test suite', () => {
254254
onChange: jasmine.createSpy('onChange')
255255
};
256256
(service as any).dynamicMatchers = [visibleMatcher];
257-
spyOn((service as any).formBuilderService, 'getTypeBindModel').and.callFake(() => bindModelAvailable ? bindModel : undefined);
258-
spyOn((service as any).formBuilderService, 'getTypeBindModelUpdates').and.returnValue(bindModelUpdates$.asObservable());
257+
((service as any).formBuilderService.getTypeBindModel as jasmine.Spy).and.callFake(() => bindModelAvailable ? bindModel : undefined);
258+
((service as any).formBuilderService.getTypeBindModelUpdates as jasmine.Spy).and.returnValue(bindModelUpdates$.asObservable());
259259

260260
const subscriptions = service.subscribeRelations(testModel, dcTypeControl);
261261
expect(visibleMatcher.onChange).toHaveBeenCalledWith(false, testModel, dcTypeControl, jasmine.anything());

0 commit comments

Comments
 (0)