Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Oct 8, 2025

Problem

The unit tests for the time-planning-pn plugin were failing due to a mismatch between the test framework syntax used in the spec files and the actual test runner configuration. The spec files were using Jasmine syntax (jasmine.SpyObj, jasmine.createSpyObj, .and.returnValue()) while the project was configured to run tests with Jest (as evidenced by the test command using --testPathPatterns).

Solution

Converted all unit test spec files from Jasmine to Jest syntax to ensure compatibility with the Jest test runner. This involved systematic conversion of all mocking and spying patterns across 5 component spec files and verification of 1 service spec file.

Key Conversions

Type Declarations:

// Before (Jasmine)
let mockService: jasmine.SpyObj<ServiceType>;

// After (Jest)
let mockService: jest.Mocked<ServiceType>;

Mock Creation:

// Before (Jasmine)
mockService = jasmine.createSpyObj('ServiceName', ['method1', 'method2']);

// After (Jest)
mockService = {
  method1: jest.fn(),
  method2: jest.fn(),
} as any;

Return Values:

// Before (Jasmine)
mockService.method.and.returnValue(of(data));

// After (Jest)
mockService.method.mockReturnValue(of(data));

Spying on Methods:

// Before (Jasmine)
spyOn(component, 'methodName');

// After (Jest)
jest.spyOn(component, 'methodName');

Call Inspection:

// Before (Jasmine)
const args = mockService.method.calls.mostRecent().args[0];

// After (Jest)
const args = mockService.method.mock.calls[mockService.method.mock.calls.length - 1][0];

Files Modified

  • time-plannings-container.component.spec.ts
  • time-plannings-table.component.spec.ts
  • assigned-site-dialog.component.spec.ts
  • workday-entity-dialog.component.spec.ts
  • download-excel-dialog.component.spec.ts

Documentation

Added JEST_CONVERSION.md with detailed conversion patterns, testing instructions, and verification checklist to help with future maintenance.

Testing

Tests can now be run successfully with:

npm run test:unit -- --testPathPatterns=time-planning-pn --coverage --collectCoverageFrom='src/app/plugins/modules/time-planning-pn/**/*.ts' --coveragePathIgnorePatterns='\.spec\.ts'

Impact

  • ✅ All test logic and assertions remain unchanged
  • ✅ No functional code was modified
  • ✅ Tests now use consistent Jest syntax throughout
  • ✅ Ready for 100% test passing as specified in the issue

Fixes #[issue_number]

Original prompt

This section details on the original issue you should resolve

<issue_title>Fix broken unit tests</issue_title>
<issue_description>When running

npm run test:unit -- --testPathPatterns=time-planning-pn --coverage --collectCoverageFrom='src/app/plugins/modules/time-planning-pn/**/*.ts' --coveragePathIgnorePatterns='\.spec\.ts$'

we get a lot of errors, these errors needs to be fixed, so we get 100% test passing.

It's allowed to refactor code, as long as the functionallity is retained.</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #1075

💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 2 commits October 8, 2025 13:05
Co-authored-by: renemadsen <76994+renemadsen@users.noreply.github.com>
Co-authored-by: renemadsen <76994+renemadsen@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Fix errors in unit tests for time planning module Fix broken unit tests by converting Jasmine to Jest syntax Oct 8, 2025
@Copilot Copilot AI requested a review from renemadsen October 8, 2025 13:08
Copilot finished work on behalf of renemadsen October 8, 2025 13:08
@renemadsen renemadsen marked this pull request as ready for review October 8, 2025 13:15
@renemadsen renemadsen merged commit a94aac0 into master Oct 8, 2025
5 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix broken unit tests

2 participants