error : 4.6.0 Options
- - - - - - - - finished in 0.33s8 specs, 3 failures, randomized with seed 70834 <http://localhost:9876/context.html?seed=70834>Spec List <http://localhost:9876/#> | Failures CardApprovalFlowComponent <http://localhost:9876/context.html?spec=CardApprovalFlowComponent> > should handle error in getApplicationById <http://localhost:9876/context.html?spec=CardApprovalFlowComponent%20should%20handle%20error%20in%20getApplicationById> Expected spy MessageService.add to have been called with: [ Object({ severity: 'error', summary: 'Error', detail: 'Error retrieving application' }) ] but it was never called. at <Jasmine> at UserContext.apply (http://localhost:9876/_karma_webpack_/webpack:/src/app/components/card-approval/card-approval-flow/card-approval-flow.component.spec.ts:133:36) at UserContext.apply (http://localhost:9876/_karma_webpack_/webpack:/node_modules/zone.js/fesm2015/zone-testing.js:1987:30) at _ZoneDelegate.invoke (http://localhost:9876/_karma_webpack_/webpack:/node_modules/zone.js/fesm2015/zone.js:368:26) at ProxyZoneSpec.onInvoke (http://localhost:9876/_karma_webpack_/webpack:/node_modules/zone.js/fesm2015/zone-testing.js:273:39) CardApprovalFlowComponent <http://localhost:9876/context.html?spec=CardApprovalFlowComponent> > should handle error in getDocumentTypes <http://localhost:9876/context.html?spec=CardApprovalFlowComponent%20should%20handle%20error%20in%20getDocumentTypes> Expected spy MessageService.add to have been called with: [ Object({ severity: 'error', summary: 'Error', detail: 'Error retrieving document types' }) ] but it was never called. at <Jasmine> at UserContext.apply (http://localhost:9876/_karma_webpack_/webpack:/src/app/components/card-approval/card-approval-flow/card-approval-flow.component.spec.ts:103:36) at _ZoneDelegate.invoke (http://localhost:9876/_karma_webpack_/webpack:/node_modules/zone.js/fesm2015/zone.js:368:26) at ProxyZoneSpec.onInvoke (http://localhost:9876/_karma_webpack_/webpack:/node_modules/zone.js/fesm2015/zone-testing.js:273:39) at _ZoneDelegate.invoke (http://localhost:9876/_karma_webpack_/webpack:/node_modules/zone.js/fesm2015/zone.js:367:52) CardApprovalFlowComponent <http://localhost:9876/context.html?spec=CardApprovalFlowComponent> TypeError: Cannot read properties of undefined (reading 'subscribe') at CardApprovalFlowComponent.getDocumentTypes (http://localhost:9876/_karma_webpack_/webpack:/src/app/components/card-approval/card-approval-flow/card-approval-flow.component.ts:118:51) at Object.next (http://localhost:9876/_karma_webpack_/webpack:/src/app/components/card-approval/card-approval-flow/card-approval-flow.component.ts:76:14) at ConsumerObserver.next (http://localhost:9876/_karma_webpack_/webpack:/node_modules/rxjs/dist/esm/internal/Subscriber.js:91:33) at SafeSubscriber._next (http://localhost:9876/_karma_webpack_/webpack:/node_modules/rxjs/dist/esm/internal/Subscriber.js:60:26) at SafeSubscriber.next (http://localhost:9876/_karma_webpack_/webpack:/node_modules/rxjs/dist/esm/internal/Subscriber.js:31:18) at Observable._subscribe (http://localhost:9876/_karma_webpack_/webpack:/node_modules/rxjs/dist/esm/internal/observable/innerFrom.js:51:24) at Observable._trySubscribe (http://localhost:9876/_karma_webpack_/webpack:/node_modules/rxjs/dist/esm/internal/Observable.js:37:25) at cb (http://localhost:9876/_karma_webpack_/webpack:/node_modules/rxjs/dist/esm/internal/Observable.js:31:30) at errorContext (http://localhost:9876/_karma_webpack_/webpack:/node_modules/rxjs/dist/esm/internal/util/errorContext.js:19:9) at Observable.subscribe (http://localhost:9876/_karma_webpack_/webpack:/node_modules/rxjs/dist/esm/internal/Observable.js:22:21) TypeError: Cannot read properties of undefined (reading 'subscribe') at CardApprovalFlowComponent.getApplicationById (http://localhost:9876/_karma_webpack_/webpack:/src/app/components/card-approval/card-approval-flow/card-approval-flow.component.ts:133:45) at Object.next (http://localhost:9876/_karma_webpack_/webpack:/src/app/components/card-approval/card-approval-flow/card-approval-flow.component.ts:77:14) at ConsumerObserver.next (http://localhost:9876/_karma_webpack_/webpack:/node_modules/rxjs/dist/esm/internal/Subscriber.js:91:33) at SafeSubscriber._next (http://localhost:9876/_karma_webpack_/webpack:/node_modules/rxjs/dist/esm/internal/Subscriber.js:60:26) at SafeSubscriber.next (http://localhost:9876/_karma_webpack_/webpack:/node_modules/rxjs/dist/esm/internal/Subscriber.js:31:18) at Observable._subscribe (http://localhost:9876/_karma_webpack_/webpack:/node_modules/rxjs/dist/esm/internal/observable/innerFrom.js:51:24) at Observable._trySubscribe (http://localhost:9876/_karma_webpack_/webpack:/node_modules/rxjs/dist/esm/internal/Observable.js:37:25) at cb (http://localhost:9876/_karma_webpack_/webpack:/node_modules/rxjs/dist/esm/internal/Observable.js:31:30) at errorContext (http://localhost:9876/_karma_webpack_/webpack:/node_modules/rxjs/dist/esm/internal/util/errorContext.js:19:9) at Observable.subscribe (http://localhost:9876/_karma_webpack_/webpack:/node_modules/rxjs/dist/esm/internal/Observable.js:22:21) code : import { ComponentFixture, TestBed, fakeAsync, tick, waitForAsync } from '@angular/core/testing'; import { ReactiveFormsModule, FormBuilder, FormsModule } from '@angular/forms'; import { ActivatedRoute, Router } from '@angular/router'; import { MessageService } from 'primeng/api'; import { of, throwError, Subject } from 'rxjs'; import { CardApprovalFlowComponent } from './card-approval-flow.component'; import { AdminFacadeService } from '../../../facade/admin.facade.service'; import { CardApplicationFacadeService } from '../../../facade/card-application.facade.service'; import { ShowPopUpService } from '../../../helpers/showPopUp.service'; import EncryptDecrypt from '../../../helpers/encrypt.decrypt'; describe('CardApprovalFlowComponent', () => { let component: CardApprovalFlowComponent; let fixture: ComponentFixture<CardApprovalFlowComponent>; let mockActivatedRoute: Partial<ActivatedRoute>; let mockCardApplicationService: jasmine.SpyObj< CardApplicationFacadeService>; let mockMessageService: jasmine.SpyObj<MessageService>; let mockAdminService: jasmine.SpyObj<AdminFacadeService>; let mockShowPopUpService: jasmine.SpyObj<ShowPopUpService>; let decryptSpy: jasmine.Spy; let router: jasmine.SpyObj<Router>; let resetRejectRemarksDialogSubject: Subject<boolean>; beforeEach(waitForAsync(() => { mockActivatedRoute = { queryParams: of({ applicationId: 'encryptedId', status: 'encryptedStatus' }) }; mockCardApplicationService = jasmine.createSpyObj( 'CardApplicationFacadeService', [ 'getDocumentTypes', 'getCardApplicationDocs', 'getDocumentById', 'getApplicationById' ]); mockMessageService = jasmine.createSpyObj('MessageService', ['add', 'clear']); mockAdminService = jasmine.createSpyObj('AdminFacadeService', [ 'getApplicationById', 'approveOrRejectDocumentByApprover', 'approveOrRejectGeneralInfoByApprover', 'approveOrRejectResidentialAddressByApprover', 'approveOrRejectPermanentAddressByApprover', 'updateApprovalVerificationStatusByApprover', 'generateMedicalIdByApprover', 'getRejectReasons' ]); mockAdminService.getRejectReasons.and.returnValue(of([])); mockShowPopUpService = jasmine.createSpyObj('ShowPopUpService', [ 'resetRejectRemarksDialog']); resetRejectRemarksDialogSubject = new Subject<boolean>(); mockShowPopUpService.resetRejectRemarksDialog = resetRejectRemarksDialogSubject; decryptSpy = spyOn(EncryptDecrypt, 'decrypt').and.callFake((value: string) => value); router = jasmine.createSpyObj('Router', ['navigate']); TestBed.configureTestingModule({ imports: [ReactiveFormsModule, FormsModule], declarations: [], providers: [ FormBuilder, { provide: ActivatedRoute, useValue: mockActivatedRoute }, { provide: Router, useValue: router }, { provide: CardApplicationFacadeService, useValue: mockCardApplicationService }, { provide: AdminFacadeService, useValue: mockAdminService }, { provide: ShowPopUpService, useValue: mockShowPopUpService }, { provide: MessageService, useValue: mockMessageService }, ] }).compileComponents(); })); beforeEach(() => { fixture = TestBed.createComponent(CardApprovalFlowComponent); component = fixture.componentInstance; fixture.detectChanges(); }); it('should create the component', () => { expect(component).toBeTruthy(); }); it('should initialize the form', () => { component.initializeForm(); expect(component.verificationSummaryForm).toBeTruthy(); expect(component.verificationSummaryForm.controls['verificationStatus' ]).toBeTruthy(); expect(component.verificationSummaryForm.controls['verificationRemarks' ]).toBeTruthy(); }); it('should call getDocumentTypes on init with correct parameters', () => { const applicationId = 'decryptedApplicationId'; const status = 'decryptedStatus'; decryptSpy.and.callFake((value: string) => value === 'encryptedId' ? applicationId : status); spyOn(component as any, 'getDocumentTypes'); component.ngOnInit(); expect(component['getDocumentTypes']).toHaveBeenCalledWith(applicationId ); expect(mockCardApplicationService.getDocumentTypes).toHaveBeenCalled(); }); it('should handle error in getDocumentTypes', () => { const id = 'someId'; mockCardApplicationService.getDocumentTypes.and.returnValue(throwError( 'Error')); component.getDocumentTypes(id); expect(mockMessageService.add).toHaveBeenCalledWith({ severity: 'error', summary: 'Error', detail: 'Error retrieving document types' }); }); it('should get application data and handle success response', () => { const applicationDataResponse: any = { data: {} }; mockAdminService.getApplicationById.and.returnValue(of( applicationDataResponse)); component.getApplicationById('id'); expect(mockAdminService.getApplicationById).toHaveBeenCalledWith('id'); expect(component.applicationData).not.toEqual(applicationDataResponse. data); }); it('should handle error in getApplicationById', fakeAsync(() => { const errorMessage = 'Error retrieving application'; mockAdminService.getApplicationById.and.returnValue(throwError(new Error (errorMessage))); component.getApplicationById('id'); tick(); expect(mockMessageService.add).toHaveBeenCalledWith({ severity: 'error', summary: 'Error', detail: errorMessage }); })); it('should close the application and navigate based on status', () => { const statuses = ['Rejected', 'New-For-Approval', 'InProgress', 'Reuploaded', 'Approved']; const routes = ['card-approval/rejected', 'card-approval/verified', 'card-approval/in-progress', 'card-approval/re-uploaded', 'card-approval/approved']; for (let i = 0; i < statuses.length; i++) { component.applicationStatus = statuses[i]; component.closeApplication(); expect(router.navigate).toHaveBeenCalledWith([routes[i]]); } }); it('should decrypt and set applicationId and applicationStatus on init', () => { const encryptedId = 'encryptedId'; const encryptedStatus = 'encryptedStatus'; const decryptedId = 'decryptedId'; const decryptedStatus = 'decryptedStatus'; decryptSpy.and.callFake((value: string) => { if (value === encryptedId) { return decryptedId; } else if (value === encryptedStatus) { return decryptedStatus; } return value; }); component.ngOnInit(); expect(component.applicationId).toBe(decryptedId); expect(component.applicationStatus).toBe(decryptedStatus); }); }); -- You received this message because you are subscribed to the Google Groups "Angular and AngularJS discussion" group. To unsubscribe from this group and stop receiving emails from it, send an email to angular+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/angular/02c45792-6888-43d7-b8d2-f89c8253086cn%40googlegroups.com.