es.davy.ai

Preguntas y respuestas de programación confiables

¿Tienes una pregunta?

Si tienes alguna pregunta, puedes hacerla a continuación o ingresar lo que estás buscando.

Pruebas unitarias de Angular

Tengo este error:

Error: No capturado (en promesa): NullInjectorError: R3InjectorError(DynamicTestModule)[UserInfoService -> UsersService -> AuthService -> InjectionToken auth0.client -> InjectionToken auth0.client]: NullInjectorError: No hay proveedor para InjectionToken auth0.client! NullInjectorError:

Mi archivo spec.ts:

describe(‘IssuingInformationComponent’, () => {
let component: IssuingInformationComponent;
let fixture: ComponentFixture;

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [ReactiveFormsModule, FormsModule, HttpClientTestingModule
,AuthModule.forRoot({
domain: ‘dgfgfg’,
clientId: ‘fgggfg’,
}),
],

    declarations: [IssuingInformationComponent],
    schemas: [ CUSTOM_ELEMENTS_SCHEMA ]
}).compileComponents().then(() => {
    fixture = TestBed.createComponent(IssuingInformationComponent);
    component = fixture.componentInstance;
    component.ngOnInit();
    fixture.detectChanges();

});

}));

Tags:  

Answer

  1. Avatar for davy.ai

    Parece que falta un proveedor para la InjectionToken auth0.client en su TestBed.configureTestingModule en el archivo spec.ts. Necesita agregar un proveedor para este token para resolver el error.


    TestBed.configureTestingModule({
    imports: [ReactiveFormsModule, FormsModule, HttpClientTestingModule
    ,AuthModule.forRoot({
    domain: 'dgfgfg',
    clientId: 'fgggfg',
    }),
    ],
    providers: [
    { provide: InjectionToken auth0.client, useValue: 'su_valor_aquí' }
    ],
    declarations: [IssuingInformationComponent],
    schemas: [ CUSTOM_ELEMENTS_SCHEMA ]
    })

Comments are closed.