import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing'; import { AssignmentModalComponent } from './assignment-modal.component'; import { BsDatepickerConfig, BsDatepickerModule, BsLocaleService } from 'ngx-bootstrap/datepicker'; import { BsModalRef } from 'ngx-bootstrap/modal'; import { FormsModule } from '@angular/forms'; export function getDatepickerConfig(): Partial { return Object.assign(new BsDatepickerConfig(), { containerClass: 'theme-blue', adaptivePosition: true, dateInputFormat: 'DD/MM/YYYY', }); } describe('AssignmentModalComponent', () => { let component: AssignmentModalComponent; let fixture: ComponentFixture; let modalRef: BsModalRef; beforeEach(waitForAsync(() => { TestBed.configureTestingModule({ declarations: [AssignmentModalComponent], imports: [BsDatepickerModule.forRoot(), FormsModule], providers: [{ provide: BsDatepickerConfig, useFactory: getDatepickerConfig }, BsModalRef], }).compileComponents(); })); beforeEach(() => { fixture = TestBed.createComponent(AssignmentModalComponent); component = fixture.componentInstance; modalRef = TestBed.inject(BsModalRef); fixture.detectChanges(); }); it('should create', () => { expect(component).toBeTruthy(); }); it('should call onClose', () => { modalRef.hide = jest.fn(); component.onCancel(); expect(modalRef.hide).toHaveBeenCalled(); }); it('should format date', () => { const date = new Date(); const formatDate = component.formatDate(date); expect(formatDate).toBeTruthy(); }); });