While testing with Angular Karma, I encountered the following error...
NullInjectorError: StaticInjectorError(DynamicTestModule)[ManageProblemsComponent -> MatDialogRef]:
StaticInjectorError(Platform: core)[ManageProblemsComponent -> MatDialogRef]:
NullInjectorError: No provider for MatDialogRef!
Component
import { Component, OnInit, Inject } from '@angular/core';
import { NbDialogRef, NB_WINDOW_CONTEXT } from '@nebular/theme';
import { ApiService } from '../../../../../app/services/api.service';
import { SmartTableData } from '../../../../@core/data/smart-table';
import { NbDialogService } from '@nebular/theme';
import { NbComponentStatus, NbGlobalPhysicalPosition, NbToastrService } from '@nebular/theme';
import { ToasterConfig } from 'angular2-toaster';
import 'style-loader!angular2-toaster/toaster.css';
import { AuthService } from '../../../../services/auth.service';
import { NgxSpinnerService } from "ngx-spinner";
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material';
import { DialogData } from '../../manage-alerts/manage-alerts.component';
import { Route, Router } from '@angular/router';
@Component({
selector: 'ngx-manage-problems',
templateUrl: './manage-problems.component.html',
styleUrls: ['./manage-problems.component.scss']
})
export class ManageProblemsComponent implements OnInit {
title: String;
myObject: any;
VendorsComponentobject: any;
CrewMembersComponentobject: any;
crewMembers:any = [];
vendorMembers:any = [];
DeliveryAgentMembers:any = [];
DeliveryAgentManagerMembers:any = [];
AdminMembers:any = [];
partialRefundStatus:any;
partialAmount:any;
issueData: any;
refundStatus: boolean;
refundReason: any = '';
buttonStatus: boolean = true;
submitClick: boolean = false;
constructor(public dialogRef: MatDialogRef<ManageProblemsComponent>,
@Inject(MAT_DIALOG_DATA) public data: DialogData,
private apiService: ApiService,
private spinner: NgxSpinnerService,
private toastrService: NbToastrService,
public router: Router
) {
this.issueData = data;
this.partialRefundStatus = false;
}
currency:any;
ngOnInit(){
this.currency =localStorage.getItem('CurrencySymbol');
localStorage.removeItem('issueDeatilsId');
localStorage.removeItem('issueType');
}
manageQueue(): void {
this.router.navigate(['/pages/orders/manage-queue',this.issueData.reporter._id])
this.dialogRef.close();
localStorage.setItem('issueDeatilsId',this.issueData._id)
localStorage.setItem('issueType',this.issueData.type)
}
close(): void {
this.dialogRef.close();
}
cancelissue(): void {
this.spinner.show();
const data2 = {
status: "closed",
actions: "resolved",
_id : this.issueData._id
}
this.apiService.changeIssueStatus(data2).subscribe((res)=>{
if(res.status == true){
if(this.issueData.orderId && this.issueData.orderId._id){
const data3 = {
status: "cancelled",
orderID : this.issueData.orderId._id
}
this.apiService.cancelOrder(data3).subscribe((res)=>{
this.dialogRef.close('success');
this.spinner.hide();
if(res.status == true){
this.showToast('success', '', 'Issue has been resolved successfully');
} else {
this.showToast('danger', '', 'Error');
}
});
} else {
this.dialogRef.close('success');
this.spinner.hide();
this.showToast('success', '', 'Issue has been resolved successfully');
}
} else {
this.dialogRef.close('success');
this.spinner.hide();
this.showToast('danger', '', 'Error');
}
});
}
}
Spec.ts
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ManageProblemsComponent } from './manage-problems.component';
import { NbCardModule } from '@nebular/theme';
import { FormsModule } from '@angular/forms';
describe('ManageProblemsComponent', () => {
let component: ManageProblemsComponent;
let fixture: ComponentFixture<ManageProblemsComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
NbCardModule,
FormsModule
],
declarations: [ ManageProblemsComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ManageProblemsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
When attempting to include,
providers: [MatDialogRef]
, I encountered
Failed: Can't resolve all parameters for MatDialogRef: (?, ?, ?).
Thank you....................................................................................................................................................................................................................................................................................