Skip to content

Commit 0f36071

Browse files
committed
Fixed test configuration
1 parent 7d25c67 commit 0f36071

8 files changed

Lines changed: 62 additions & 25 deletions

File tree

src/app/app.component.spec.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,4 @@ describe('AppComponent', () => {
2020
expect(app).toBeTruthy();
2121
});
2222

23-
it(`should have as title 'angular-http-basic-auth-example'`, () => {
24-
const fixture = TestBed.createComponent(AppComponent);
25-
const app = fixture.componentInstance;
26-
expect(app.title).toEqual('angular-http-basic-auth-example');
27-
});
28-
29-
it('should render title', () => {
30-
const fixture = TestBed.createComponent(AppComponent);
31-
fixture.detectChanges();
32-
const compiled = fixture.nativeElement as HTMLElement;
33-
expect(compiled.querySelector('.content span')?.textContent).toContain('angular-http-basic-auth-example app is running!');
34-
});
3523
});

src/app/authentication/guard/authenticated.guard.spec.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1+
import { HttpClientTestingModule } from '@angular/common/http/testing';
12
import { TestBed } from '@angular/core/testing';
2-
3+
import { RouterTestingModule } from '@angular/router/testing';
34
import { AuthenticatedGuard } from './authenticated.guard';
45

56
describe('AuthenticatedGuard', () => {
67
let guard: AuthenticatedGuard;
78

89
beforeEach(() => {
9-
TestBed.configureTestingModule({});
10+
TestBed.configureTestingModule({
11+
imports: [
12+
HttpClientTestingModule,
13+
RouterTestingModule
14+
]
15+
});
1016
guard = TestBed.inject(AuthenticatedGuard);
1117
});
1218

src/app/authentication/interceptor/authentication.interceptor.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
import { HttpClientTestingModule } from '@angular/common/http/testing';
12
import { TestBed } from '@angular/core/testing';
23

34
import { AuthenticationInterceptor } from './authentication.interceptor';
45

56
describe('AuthenticationInterceptor', () => {
67
beforeEach(() => TestBed.configureTestingModule({
8+
imports: [
9+
HttpClientTestingModule
10+
],
711
providers: [
812
AuthenticationInterceptor
913
]

src/app/authentication/service/authentication.service.spec.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1+
import { HttpClientTestingModule } from '@angular/common/http/testing';
12
import { TestBed } from '@angular/core/testing';
2-
33
import { AuthenticationService } from './authentication.service';
44

55
describe('AuthenticationService', () => {
66
let service: AuthenticationService;
77

88
beforeEach(() => {
9-
TestBed.configureTestingModule({});
9+
TestBed.configureTestingModule({
10+
imports: [
11+
HttpClientTestingModule
12+
]
13+
});
1014
service = TestBed.inject(AuthenticationService);
1115
});
1216

src/app/data/data-list/data-list.component.spec.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import { HttpClientTestingModule } from '@angular/common/http/testing';
12
import { ComponentFixture, TestBed } from '@angular/core/testing';
2-
3+
import { DataService } from '../service/data.service';
34
import { DataListComponent } from './data-list.component';
45

56
describe('DataListComponent', () => {
@@ -8,9 +9,17 @@ describe('DataListComponent', () => {
89

910
beforeEach(async () => {
1011
await TestBed.configureTestingModule({
11-
declarations: [ DataListComponent ]
12+
imports: [
13+
HttpClientTestingModule
14+
],
15+
declarations: [
16+
DataListComponent
17+
],
18+
providers: [
19+
DataService
20+
]
1221
})
13-
.compileComponents();
22+
.compileComponents();
1423
});
1524

1625
beforeEach(() => {

src/app/data/service/data.service.spec.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
1+
import { HttpClient } from '@angular/common/http';
2+
import { HttpClientTestingModule } from '@angular/common/http/testing';
13
import { TestBed } from '@angular/core/testing';
2-
34
import { DataService } from './data.service';
45

56
describe('DataService', () => {
67
let service: DataService;
8+
let httpClient: HttpClient;
79

810
beforeEach(() => {
9-
TestBed.configureTestingModule({});
11+
TestBed.configureTestingModule({
12+
imports: [
13+
HttpClientTestingModule
14+
],
15+
providers: [
16+
DataService
17+
]
18+
});
19+
httpClient = TestBed.inject(HttpClient);
1020
service = TestBed.inject(DataService);
1121
});
1222

src/app/login/login-form/login-form.component.spec.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
import { HttpClientTestingModule } from '@angular/common/http/testing';
12
import { ComponentFixture, TestBed } from '@angular/core/testing';
3+
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
4+
import { RouterTestingModule } from '@angular/router/testing';
25

36
import { LoginFormComponent } from './login-form.component';
47

@@ -8,9 +11,15 @@ describe('LoginFormComponent', () => {
811

912
beforeEach(async () => {
1013
await TestBed.configureTestingModule({
11-
declarations: [ LoginFormComponent ]
14+
imports: [
15+
ReactiveFormsModule,
16+
FormsModule,
17+
HttpClientTestingModule,
18+
RouterTestingModule
19+
],
20+
declarations: [LoginFormComponent]
1221
})
13-
.compileComponents();
22+
.compileComponents();
1423
});
1524

1625
beforeEach(() => {

src/app/login/logout-button/logout-button.component.spec.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import { HttpClientTestingModule } from '@angular/common/http/testing';
12
import { ComponentFixture, TestBed } from '@angular/core/testing';
2-
3+
import { RouterTestingModule } from '@angular/router/testing';
34
import { LogoutButtonComponent } from './logout-button.component';
45

56
describe('LogoutButtonComponent', () => {
@@ -8,7 +9,13 @@ describe('LogoutButtonComponent', () => {
89

910
beforeEach(async () => {
1011
await TestBed.configureTestingModule({
11-
declarations: [ LogoutButtonComponent ]
12+
imports: [
13+
HttpClientTestingModule,
14+
RouterTestingModule
15+
],
16+
declarations: [
17+
LogoutButtonComponent
18+
]
1219
})
1320
.compileComponents();
1421
});

0 commit comments

Comments
 (0)