Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 9: NULLINJECTORERROR: NO PROVIDER FOR NGXSMARTMODALSERVICE

Here I attached my spec files.

actionService.spec.ts

import { TestBed } from '@angular/core/testing';
import { NgxSmartModalService } from 'ngx-smart-modal';
import { ActionService } from './action.service';

describe('ActionService', () => {
    let service: ActionService;

    beforeEach(() => {    
    TestBed.configureTestingModule({
        providers: [NgxSmartModalService]
    });
    service = TestBed.inject(ActionService);
    });

    it('should be created', () => {
    expect(service).toBeTruthy();
    });
});

MultiNumberComponent.spec.ts

import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ActionService } from '../services/action/action.service';
import { MultiNumberComponent } from './multi-number.component';
import { MatDialogModule } from '@angular/material/dialog';
import { HttpTestingController, HttpClientTestingModule } from '@angular/common/http/testing';
import { HttpClient } from 'selenium-webdriver/http';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { CircleProgressComponent } from './../circle-progress/circle-progress.component';
import { PieChartComponent } from './../pie-chart/pie-chart.component';
    
describe('MultiNumberComponent', () => {
    let component: MultiNumberComponent;
    let fixture: ComponentFixture<MultiNumberComponent>;

    beforeEach(async(() => {
    TestBed.configureTestingModule({
        imports: [MatDialogModule, HttpClientTestingModule],
        declarations: [ MultiNumberComponent, PieChartComponent, CircleProgressComponent],
        providers: [ ActionService ],
        schemas: [NO_ERRORS_SCHEMA]
    }).compileComponents().then( result => {
    fixture = TestBed.createComponent(MultiNumberComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
    })
    }));
    
    it('should create', () => {
    expect(component).toBeTruthy();
    });
    
});

When I do the "npm run test" I'm getting the following error.

1 SPEC, 1 FAILURE, RANDOMIZED WITH SEED 66295SPEC LIST | FAILURES MULTINUMBERCOMPONENT > SHOULD CREATE FAILED: UNCAUGHT (IN PROMISE): NULLINJECTORERROR: R3INJECTORERROR(DYNAMICTESTMODULE)[ACTIONSERVICE -> NGXSMARTMODALSERVICE -> NGXSMARTMODALSERVICE]: NULLINJECTORERROR: NO PROVIDER FOR NGXSMARTMODALSERVICE!

can anyone help to fix this error?

like image 720
Nirmattha Rao Avatar asked Oct 26 '25 14:10

Nirmattha Rao


1 Answers

Try adding NgxSmartModalModule in the imports of your spec file like:

imports: [MatDialogModule, HttpClientTestingModule, NgxSmartModalModule]
like image 129
Sai Vamsi Avatar answered Oct 29 '25 19:10

Sai Vamsi