Reputation: 1994
I am testing a component that uses ngx-permissions but I get the error - NullInjectorError: StaticInjectorError(DynamicTestModule)[NgxPermissionsDirective -> NgxPermissionsService]... yet I have imported the module. My test bed is configured as shown below:
TestBed.configureTestingModule({
declarations: [ApplicationDetailsComponent],
imports: [
SharedModule,
PipeModule,
MaterialModule,
NgxLoadingModule,
RouterTestingModule,
HttpClientTestingModule,
ToasterTestingModule,
NoopAnimationsModule,
FlexLayoutModule,
ReactiveFormsModule,
NgxPermissionsModule,
],
providers: [
{
provide: AuthService,
useClass: MockAuthService,
},
{
provide: AnotherService,
useClass: AnotherServiceMock,
},
{
provide: ActivatedRoute,
useValue: {...route},
},
],
}).compileComponents();
Upvotes: 1
Views: 1679
Reputation: 89
import {
NgxPermissionsAllowStubDirective,
NgxPermissionsModule,
} from 'ngx-permissions';
describe('TestComponentA', () => {
let component: ComponentA;
let fixture: ComponentFixture<ComponentA>;
let service: ComponentAService;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [
NgxPermissionsModule.forRoot(),
],
declarations: [ComponentA, NgxPermissionsAllowStubDirective],
providers: [],
}).compileComponents();
});
})
Upvotes: 3