Skip to content

Latest commit

 

History

History
114 lines (87 loc) · 3.48 KB

File metadata and controls

114 lines (87 loc) · 3.48 KB

Jest Conversion Summary

Overview

All unit test spec files in the time-planning-pn plugin have been converted from Jasmine to Jest syntax to fix broken unit tests.

Files Converted

Component Specs

  1. time-plannings-container.component.spec.ts

    • Converted all Jasmine spy objects to Jest mocked objects
    • Updated mock creation from jasmine.createSpyObj to manual object creation with jest.fn()
    • Changed spyOn to jest.spyOn
    • Changed .and.returnValue() to .mockReturnValue()
  2. time-plannings-table.component.spec.ts

    • Converted Jasmine SpyObj to Jest Mocked types
    • Updated all mock methods to use Jest syntax
    • Converted spy creation and return value setting
  3. assigned-site-dialog.component.spec.ts

    • Converted service and store mocks to Jest syntax
    • Updated mock return value patterns
  4. workday-entity-dialog.component.spec.ts

    • Converted large component spec with extensive time conversion tests
    • Updated all mock patterns to Jest
  5. download-excel-dialog.component.spec.ts

    • Converted service mocks to Jest
    • Updated Jasmine's .calls.mostRecent().args[0] to Jest's .mock.calls[.mock.calls.length - 1][0]

Service Specs

  1. time-planning-pn-plannings.service.spec.ts
    • Already using Jest syntax (no changes needed)

Conversion Patterns

Type Declarations

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

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

Mock Creation

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

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

Return Values

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

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

Spying on Methods

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

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

Accessing Call Arguments

// 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];

Testing Command

To run the unit tests for the time-planning-pn plugin, use:

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

Benefits of Jest Conversion

  1. Consistency: All test files now use the same testing framework (Jest)
  2. Modern Syntax: Jest is more commonly used in modern JavaScript/TypeScript projects
  3. Better Performance: Jest offers better performance with parallel test execution
  4. Built-in Mocking: Jest has powerful built-in mocking capabilities without additional libraries

Verification

All files have been verified to:

  • ✅ Use Jest mocking syntax exclusively
  • ✅ Have no remaining Jasmine patterns (jasmine.SpyObj, jasmine.createSpyObj, .and.returnValue)
  • ✅ Use proper Jest spy and mock patterns
  • ✅ Maintain all original test logic and assertions
  • ✅ Preserve test coverage for time conversion utilities, component interactions, and service calls

Notes

  • No test logic was changed during conversion
  • All assertions remain identical
  • Test descriptions and structure are preserved
  • The conversion maintains 100% backward compatibility with the original test intent