NullInjectorError: StaticInjectorError(DynamicTestModule)[ToastrService -> InjectionToken ToastConfig]: in tslint angular 8
import { ToastrModule } from 'ngx-toastr';
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [ToastrModule.forRoot()],
})
.compileComponents();
}));
Add ToastrModule.forRoot() in imports as shown above and your error might be resolved
These approaches did not work for me. I had to provide my own value for the provider. This is what worked for me:
First, I declared my own "dummy" implementation:
const toastrService = {
success: (message?: string, title?: string, override?: Partial<IndividualConfig>) => { },
error: (message?: string, title?: string, override?: Partial<IndividualConfig>) => { }
};
Then, I indicated the value to use in the providers section:
providers: [
...
{ provide: ToastrService, useValue: toastrService },
],