I have tried defining authService in my spec file as follows:
beforeEach(() => {
authService = TestBed.inject(AuthService);
}
But I get the following error:
NullInjectorError: R3InjectorError(DynamicTestModule)[AuthService → InjectionToken auth0.client → InjectionToken auth0.client]:
NullInjectorError: No provider for InjectionToken auth0.client!
Please let me know how to test the Angular SDK AuthService
We don’t have specific guidance on how to run tests for specific parts of our stack. We only offer general guidance on testing your integrations with Auth0 stack. More on that here:
Is there a way to write the unit test cases for @auth0/auth0-angular SDK or are there any examples on this? I need to be able to mock the AuthService or test it in any possible way. I could not find anything on this based on the links.
@Kia.kia & @andrew.p1 (and all others coming across this later):
I could solve this by making sure that I have the AuthModule.forRoot({...}) also in the imports array of the TestBed of each *.spec.ts file:
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
...,
AuthModule.forRoot({
domain: 'YOURTENANTDOMAIN.DATACENTER.auth0.com',
clientId: '...',
}),
],
}).compileComponents(); // edit 1: this compileComponents() call is only needed if you have to import other components that require it to run the test
In further development of my current project I will try to learn more if you need to have valid credentials in there or not. I hope I will not forget to update this once I have done a bit more with it.
@konrad.sopala I am slightly disappointed that you don’t find anything about this in the Quickstarters that are provided - no hints, no examples, no best practices. Unit testing is nothing new or fancy, so having it included in your guides would be an improvement that we should not need to ask for…
Hey there Manuel! Totally understand that but in order to fight for it for you it will be best if you can create such topic providing all the necessary context in our Feedback category here: