Skip to content

Commit c061d70

Browse files
Copilotrenemadsen
andcommitted
Fix Jasmine compatibility layer for Jest tests
- Added 'calls' property to mock objects with reset(), count(), any(), all(), mostRecent() methods - Created MockTranslatePipe to fix NG0302 translate pipe errors - Fixed worker-edit-create tests by adding MockTranslatePipe declaration - Tests passing increased from 29 to 39 (+10 tests) - Test suites passing increased from 4 to 7 (+3 suites) Co-authored-by: renemadsen <[email protected]>
1 parent a30f472 commit c061d70

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

eform-client/src/app/modules/advanced/components/workers/worker-edit-create/worker-edit-create.component.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { WorkersService, DeviceUserService } from 'src/app/common/services';
55
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
66
import { of } from 'rxjs';
77
import { WorkerDto, CommonDictionaryModel, OperationDataResult, OperationResult } from 'src/app/common/models';
8+
import { MockTranslatePipe } from 'src/test-helpers';
89

910
describe('WorkerEditCreateComponent', () => {
1011
let component: WorkerEditCreateComponent;
@@ -21,7 +22,7 @@ describe('WorkerEditCreateComponent', () => {
2122
mockDialogData = new WorkerDto();
2223

2324
TestBed.configureTestingModule({
24-
declarations: [WorkerEditCreateComponent],
25+
declarations: [WorkerEditCreateComponent, MockTranslatePipe],
2526
providers: [
2627
{ provide: WorkersService, useValue: mockWorkersService },
2728
{ provide: DeviceUserService, useValue: mockDeviceUserService },

eform-client/src/setup-jest.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ getTestBed().initTestEnvironment(
2020
const obj: any = {};
2121
methodNames.forEach((methodName) => {
2222
obj[methodName] = jest.fn();
23+
// Add Jasmine-style 'and' API
2324
obj[methodName].and = {
2425
returnValue: (value: any) => {
2526
obj[methodName].mockReturnValue(value);
@@ -32,6 +33,25 @@ getTestBed().initTestEnvironment(
3233
return obj[methodName];
3334
}
3435
};
36+
// Add Jasmine-style 'calls' API for compatibility
37+
obj[methodName].calls = {
38+
reset: () => {
39+
obj[methodName].mockClear();
40+
},
41+
count: () => {
42+
return obj[methodName].mock.calls.length;
43+
},
44+
any: () => {
45+
return obj[methodName].mock.calls.length > 0;
46+
},
47+
all: () => {
48+
return obj[methodName].mock.calls;
49+
},
50+
mostRecent: () => {
51+
const calls = obj[methodName].mock.calls;
52+
return calls.length > 0 ? { args: calls[calls.length - 1] } : undefined;
53+
}
54+
};
3555
});
3656
return obj;
3757
},
@@ -47,6 +67,25 @@ getTestBed().initTestEnvironment(
4767
return spy;
4868
}
4969
};
70+
// Add Jasmine-style 'calls' API
71+
(spy as any).calls = {
72+
reset: () => {
73+
spy.mockClear();
74+
},
75+
count: () => {
76+
return spy.mock.calls.length;
77+
},
78+
any: () => {
79+
return spy.mock.calls.length > 0;
80+
},
81+
all: () => {
82+
return spy.mock.calls;
83+
},
84+
mostRecent: () => {
85+
const calls = spy.mock.calls;
86+
return calls.length > 0 ? { args: calls[calls.length - 1] } : undefined;
87+
}
88+
};
5089
return spy;
5190
}
5291
};

eform-client/src/test-helpers.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Pipe, PipeTransform } from '@angular/core';
2+
3+
/**
4+
* Mock TranslatePipe for testing
5+
* Returns the key as-is or a simple transformed version
6+
*/
7+
@Pipe({
8+
name: 'translate',
9+
standalone: false
10+
})
11+
export class MockTranslatePipe implements PipeTransform {
12+
transform(value: any): any {
13+
return value;
14+
}
15+
}

0 commit comments

Comments
 (0)