You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: TEST_FIXES.md
+34-12Lines changed: 34 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,57 +10,79 @@ The Angular unit tests were failing with errors like:
10
10
These errors occurred because Angular's test compiler was trying to compile the component templates and couldn't find the declarations for various directives and pipes used in the templates (like Material components, translate pipe, mtx-grid, etc.).
11
11
12
12
## Solution
13
-
Added `NO_ERRORS_SCHEMA` to all component test specs. This schema tells Angular to ignore unknown elements and attributes during template compilation, which is appropriate for unit tests that focus on component logic rather than template rendering.
13
+
Added `NO_ERRORS_SCHEMA` to all component test specsto ignore unknown elements and attributes, AND imported `TranslateModule` to provide the `translate` pipe.
14
14
15
-
`NO_ERRORS_SCHEMA` is a testing best practice for unit tests because:
16
-
1.**Minimal changes** - Only requires adding one line to each test configuration
17
-
2.**Isolation** - Unit tests should focus on component logic, not template rendering
18
-
3.**Simplicity** - Avoids importing dozens of Angular Material and other modules
19
-
4.**Performance** - Tests run faster without compiling full module trees
15
+
**Important Note:**`NO_ERRORS_SCHEMA` only ignores unknown elements and attributes - it does NOT ignore missing pipes. Since all component templates use the `translate` pipe, we must import `TranslateModule.forRoot()` in the test configuration.
16
+
17
+
This combined approach is appropriate for unit tests because:
18
+
1.**Focus on Logic** - Unit tests should test component logic, not template rendering
19
+
2.**Minimal Changes** - Only requires adding imports and one line to config
20
+
3.**Performance** - Tests run faster without compiling full module trees for Material components
21
+
4.**Handles Pipes** - TranslateModule provides the translate pipe that NO_ERRORS_SCHEMA cannot ignore
20
22
5.**Maintenance** - Less brittle when templates change
21
23
22
24
## Files Modified
23
25
24
26
1.**time-plannings-table.component.spec.ts**
25
27
- Added `NO_ERRORS_SCHEMA` import
28
+
- Added `TranslateModule` import
26
29
- Added `schemas: [NO_ERRORS_SCHEMA]` to TestBed configuration
30
+
- Added `TranslateModule.forRoot()` to imports array
27
31
28
32
2.**time-plannings-container.component.spec.ts**
29
33
- Added `NO_ERRORS_SCHEMA` import
34
+
- Added `TranslateModule` import
30
35
- Added `schemas: [NO_ERRORS_SCHEMA]` to TestBed configuration
36
+
- Added `TranslateModule.forRoot()` to imports array
31
37
32
38
3.**assigned-site-dialog.component.spec.ts**
33
39
- Added `NO_ERRORS_SCHEMA` import
40
+
- Added `TranslateModule` import
34
41
- Added `schemas: [NO_ERRORS_SCHEMA]` to TestBed configuration
42
+
- Added `TranslateModule.forRoot()` to imports array
35
43
36
44
4.**workday-entity-dialog.component.spec.ts**
37
45
- Added `NO_ERRORS_SCHEMA` import
46
+
- Added `TranslateModule` import
38
47
- Added `schemas: [NO_ERRORS_SCHEMA]` to TestBed configuration
48
+
- Added `TranslateModule.forRoot()` to imports array
39
49
40
50
5.**download-excel-dialog.component.spec.ts**
41
51
- Added `NO_ERRORS_SCHEMA` import
52
+
- Added `TranslateModule` import
42
53
- Added `schemas: [NO_ERRORS_SCHEMA]` to TestBed configuration
54
+
- Added `TranslateModule.forRoot()` to imports array
43
55
44
56
## Change Summary
45
57
-**5 files changed**
46
-
-**10 insertions(+)**, **1 deletion(-)**
47
-
- All changes are additive and minimal
58
+
-**15 insertions(+)**, **5 deletions(-)**
59
+
- All changes are minimal and focused
48
60
49
61
## Testing
50
62
To run the tests, use the command specified in the issue:
51
63
```bash
52
64
npm run test:unit -- --testPathPatterns=time-planning-pn --coverage --collectCoverageFrom='src/app/plugins/modules/time-planning-pn/**/*.ts' --coveragePathIgnorePatterns='\.spec\.ts'
53
65
```
54
66
55
-
## Alternative Approach (Not Used)
56
-
The alternative would have been to import all the required modules in each test:
57
-
-`TranslateModule.forRoot()`
67
+
## Why This Approach Works
68
+
69
+
### NO_ERRORS_SCHEMA handles:
70
+
- Unknown elements (mat-tab, mat-form-field, mat-button, etc.)
Copy file name to clipboardExpand all lines: eform-client/src/app/plugins/modules/time-planning-pn/components/plannings/time-planning-actions/assigned-site/assigned-site-dialog.component.spec.ts
+2-1Lines changed: 2 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,7 @@ import { TimePlanningPnSettingsService } from '../../../../services';
Copy file name to clipboardExpand all lines: eform-client/src/app/plugins/modules/time-planning-pn/components/plannings/time-planning-actions/download-excel/download-excel-dialog.component.spec.ts
+2Lines changed: 2 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,7 @@ import { ToastrService } from 'ngx-toastr';
Copy file name to clipboardExpand all lines: eform-client/src/app/plugins/modules/time-planning-pn/components/plannings/time-planning-actions/workday-entity/workday-entity-dialog.component.spec.ts
+2-1Lines changed: 2 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,7 @@ import { TranslateService } from '@ngx-translate/core';
Copy file name to clipboardExpand all lines: eform-client/src/app/plugins/modules/time-planning-pn/components/plannings/time-plannings-container/time-plannings-container.component.spec.ts
+2Lines changed: 2 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,7 @@ import { Store } from '@ngrx/store';
Copy file name to clipboardExpand all lines: eform-client/src/app/plugins/modules/time-planning-pn/components/plannings/time-plannings-table/time-plannings-table.component.spec.ts
+2Lines changed: 2 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,7 @@ import { DatePipe } from '@angular/common';
0 commit comments