Add HttpClient and Router testing modules to test.

This commit is contained in:
Spencer Ofwiti 2021-06-24 20:51:06 +03:00
parent 7e93aea96f
commit 78a8558882
9 changed files with 27 additions and 6 deletions

View File

@ -100,5 +100,9 @@
"hooks": {
"pre-commit": "npx pretty-quick --staged && npm run format:lint && npx lint-staged"
}
},
"browser": {
"child_process": false,
"fs": false
}
}

View File

@ -3,12 +3,15 @@ import { TestBed } from '@angular/core/testing';
// Application imports
import { AuthGuard } from '@app/_guards/auth.guard';
import {RouterTestingModule} from '@angular/router/testing';
describe('AuthGuard', () => {
let guard: AuthGuard;
beforeEach(() => {
TestBed.configureTestingModule({});
TestBed.configureTestingModule({
imports: [RouterTestingModule]
});
guard = TestBed.inject(AuthGuard);
});

View File

@ -3,12 +3,15 @@ import { TestBed } from '@angular/core/testing';
// Application imports
import { RoleGuard } from '@app/_guards/role.guard';
import {RouterTestingModule} from '@angular/router/testing';
describe('RoleGuard', () => {
let guard: RoleGuard;
beforeEach(() => {
TestBed.configureTestingModule({});
TestBed.configureTestingModule({
imports: [RouterTestingModule]
});
guard = TestBed.inject(RoleGuard);
});

View File

@ -1,12 +1,15 @@
import { TestBed } from '@angular/core/testing';
import { AuthService } from '@app/_services/auth.service';
import {HttpClientTestingModule} from '@angular/common/http/testing';
describe('AuthService', () => {
let service: AuthService;
beforeEach(() => {
TestBed.configureTestingModule({});
TestBed.configureTestingModule({
imports: [HttpClientTestingModule]
});
service = TestBed.inject(AuthService);
});

View File

@ -1,12 +1,15 @@
import { TestBed } from '@angular/core/testing';
import { LocationService } from '@app/_services/location.service';
import {HttpClientTestingModule} from '@angular/common/http/testing';
describe('LocationService', () => {
let service: LocationService;
beforeEach(() => {
TestBed.configureTestingModule({});
TestBed.configureTestingModule({
imports: [HttpClientTestingModule]
});
service = TestBed.inject(LocationService);
});

View File

@ -8,11 +8,12 @@ import {
TopbarStubComponent,
TransactionServiceStub,
} from '@src/testing';
import {HttpClientTestingModule} from '@angular/common/http/testing';
describe('AppComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [RouterTestingModule],
imports: [HttpClientTestingModule, RouterTestingModule],
declarations: [AppComponent, FooterStubComponent, SidebarStubComponent, TopbarStubComponent],
providers: [{ provide: TransactionService, useClass: TransactionServiceStub }],
}).compileComponents();

View File

@ -1,6 +1,7 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { AuthComponent } from '@app/auth/auth.component';
import {HttpClientTestingModule} from '@angular/common/http/testing';
describe('AuthComponent', () => {
let component: AuthComponent;
@ -8,6 +9,7 @@ describe('AuthComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
declarations: [AuthComponent],
}).compileComponents();
});

View File

@ -48,7 +48,7 @@ describe('AdminComponent', () => {
it('#approveAction should toggle approval status', () => {
const action = userService.getActionById('1');
expect(action).toBe({
expect(action).toEqual({
id: 1,
user: 'Tom',
role: 'enroller',

View File

@ -1,6 +1,7 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { TransactionDetailsComponent } from '@pages/transactions/transaction-details/transaction-details.component';
import {RouterTestingModule} from '@angular/router/testing';
describe('TransactionDetailsComponent', () => {
let component: TransactionDetailsComponent;
@ -8,6 +9,7 @@ describe('TransactionDetailsComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [RouterTestingModule],
declarations: [TransactionDetailsComponent],
}).compileComponents();
});