Skip to content

Commit a1d37e8

Browse files
Update example app
1 parent c4157f5 commit a1d37e8

File tree

2 files changed

+33
-28
lines changed

2 files changed

+33
-28
lines changed

projects/playground/src/app/app.component.spec.ts

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import { AppComponent } from './app.component';
55
import { AuthService } from '../../../auth0-angular/src/lib/auth.service';
66
import { BehaviorSubject, of, ReplaySubject } from 'rxjs';
77
import { ReactiveFormsModule } from '@angular/forms';
8-
import { HttpClientModule } from '@angular/common/http';
8+
import {
9+
provideHttpClient,
10+
withInterceptorsFromDi,
11+
} from '@angular/common/http';
912
import { expect } from '@jest/globals';
1013

1114
describe('AppComponent', () => {
@@ -29,13 +32,14 @@ describe('AppComponent', () => {
2932
} as any;
3033

3134
TestBed.configureTestingModule({
32-
imports: [RouterTestingModule, ReactiveFormsModule, HttpClientModule],
3335
declarations: [AppComponent],
36+
imports: [RouterTestingModule, ReactiveFormsModule],
3437
providers: [
3538
{
3639
provide: AuthService,
3740
useValue: authMock,
3841
},
42+
provideHttpClient(withInterceptorsFromDi()),
3943
],
4044
}).compileComponents();
4145

@@ -84,7 +88,8 @@ describe('AppComponent', () => {
8488
describe('when user is authenticated', () => {
8589
beforeEach(() => {
8690
const loading = authMock.isLoading$ as BehaviorSubject<boolean>;
87-
const authenticated = authMock.isAuthenticated$ as BehaviorSubject<boolean>;
91+
const authenticated =
92+
authMock.isAuthenticated$ as BehaviorSubject<boolean>;
8893
const user = authMock.user$ as BehaviorSubject<any>;
8994

9095
loading.next(false);
@@ -189,9 +194,9 @@ describe('AppComponent', () => {
189194
);
190195
const form = component.accessTokenOptionsForm.controls;
191196
form['usePopup'].setValue(false);
192-
((authMock.getAccessTokenSilently as unknown) as jest.SpyInstance).mockReturnValue(
193-
of('access token silently')
194-
);
197+
(
198+
authMock.getAccessTokenSilently as unknown as jest.SpyInstance
199+
).mockReturnValue(of('access token silently'));
195200

196201
const btnRefresh = divToken.querySelector('button');
197202
btnRefresh?.click();
@@ -212,9 +217,9 @@ describe('AppComponent', () => {
212217
const form = component.accessTokenOptionsForm.controls;
213218
form['usePopup'].setValue(false);
214219
form['ignoreCache'].setValue(false);
215-
((authMock.getAccessTokenSilently as unknown) as jest.SpyInstance).mockReturnValue(
216-
of('access token silently')
217-
);
220+
(
221+
authMock.getAccessTokenSilently as unknown as jest.SpyInstance
222+
).mockReturnValue(of('access token silently'));
218223

219224
const btnRefresh = divToken.querySelector('button');
220225
btnRefresh?.click();
@@ -235,9 +240,9 @@ describe('AppComponent', () => {
235240
const form = component.accessTokenOptionsForm.controls;
236241
form['usePopup'].setValue(false);
237242
form['ignoreCache'].setValue(true);
238-
((authMock.getAccessTokenSilently as unknown) as jest.SpyInstance).mockReturnValue(
239-
of('access token silently')
240-
);
243+
(
244+
authMock.getAccessTokenSilently as unknown as jest.SpyInstance
245+
).mockReturnValue(of('access token silently'));
241246

242247
const btnRefresh = divToken.querySelector('button');
243248
btnRefresh?.click();
@@ -257,9 +262,9 @@ describe('AppComponent', () => {
257262
);
258263
const form = component.accessTokenOptionsForm.controls;
259264
form['usePopup'].setValue(true);
260-
((authMock.getAccessTokenWithPopup as unknown) as jest.SpyInstance).mockReturnValue(
261-
of('access token popup')
262-
);
265+
(
266+
authMock.getAccessTokenWithPopup as unknown as jest.SpyInstance
267+
).mockReturnValue(of('access token popup'));
263268

264269
const btnRefresh = divToken.querySelector('button');
265270
btnRefresh?.click();
@@ -274,7 +279,8 @@ describe('AppComponent', () => {
274279
describe('when user is not authenticated', () => {
275280
beforeEach(() => {
276281
const loading = authMock.isLoading$ as BehaviorSubject<boolean>;
277-
const authenticated = authMock.isAuthenticated$ as BehaviorSubject<boolean>;
282+
const authenticated =
283+
authMock.isAuthenticated$ as BehaviorSubject<boolean>;
278284

279285
loading.next(false);
280286
authenticated.next(false);

projects/playground/src/app/app.module.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import { BrowserModule } from '@angular/platform-browser';
22
import { NgModule, APP_INITIALIZER } from '@angular/core';
33
import {
44
HttpClient,
5-
HttpClientModule,
65
HTTP_INTERCEPTORS,
76
HttpBackend,
7+
provideHttpClient,
8+
withInterceptorsFromDi,
89
} from '@angular/common/http';
910
import { AuthModule } from 'projects/auth0-angular/src/lib/auth.module';
1011
import { AuthHttpInterceptor } from 'projects/auth0-angular/src/lib/auth.interceptor';
@@ -25,14 +26,13 @@ import { AuthClientConfig } from 'projects/auth0-angular/src/lib/auth.config';
2526
* @param handler The HttpBackend instance used to instantiate HttpClient manually
2627
* @param config The AuthConfigClient service
2728
*/
28-
const configInitializer = (
29-
handler: HttpBackend,
30-
config: AuthClientConfig
31-
): (() => Promise<any>) => () =>
32-
new HttpClient(handler)
33-
.get('/assets/config.json')
34-
.toPromise()
35-
.then((loadedConfig: any) => config.set(loadedConfig)); // Set the config that was loaded asynchronously here
29+
const configInitializer =
30+
(handler: HttpBackend, config: AuthClientConfig): (() => Promise<any>) =>
31+
() =>
32+
new HttpClient(handler)
33+
.get('/assets/config.json')
34+
.toPromise()
35+
.then((loadedConfig: any) => config.set(loadedConfig)); // Set the config that was loaded asynchronously here
3636

3737
@NgModule({
3838
declarations: [
@@ -43,12 +43,11 @@ const configInitializer = (
4343
NestedChildRouteComponent,
4444
ErrorComponent,
4545
],
46+
bootstrap: [AppComponent],
4647
imports: [
4748
BrowserModule,
4849
AppRoutingModule,
4950
ReactiveFormsModule,
50-
HttpClientModule,
51-
5251
// This playground has been configured by default to use dynamic configuration.
5352
// If you wish to specify configuration to `forRoot` directly, uncomment `authConfig`
5453
// here, and comment out the APP_INITIALIZER config in the providers array below.
@@ -62,7 +61,7 @@ const configInitializer = (
6261
multi: true,
6362
},
6463
{ provide: HTTP_INTERCEPTORS, useClass: AuthHttpInterceptor, multi: true },
64+
provideHttpClient(withInterceptorsFromDi()),
6565
],
66-
bootstrap: [AppComponent],
6766
})
6867
export class AppModule {}

0 commit comments

Comments
 (0)