Skip to content

Commit

Permalink
Assignment service tests
Browse files Browse the repository at this point in the history
  • Loading branch information
subchannel13 committed Apr 24, 2024
1 parent b4ed2af commit 970d5cf
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
4 changes: 3 additions & 1 deletion frontend/src/app/dashboard/dashboard.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { DashboardComponent } from './dashboard.component';
import { provideHttpClient } from '@angular/common/http';

describe('DashboardComponent', () => {
let component: DashboardComponent;
let fixture: ComponentFixture<DashboardComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [DashboardComponent]
imports: [DashboardComponent],
providers: [provideHttpClient()]
})
.compileComponents();

Expand Down
42 changes: 34 additions & 8 deletions frontend/src/app/data/assignment.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,42 @@
import { TestBed } from '@angular/core/testing';
import {
HttpClientTestingModule,
HttpTestingController,
} from '@angular/common/http/testing';

import { AssignmentService } from './assignment.service';
import { Assignment } from './assignment.model';

const mockEntity = new Assignment(1, "Test task");

describe('AssignmentService', () => {
let service: AssignmentService;
let service: AssignmentService;
let httpController: HttpTestingController;

beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
});

service = TestBed.inject(AssignmentService);
httpController = TestBed.inject(HttpTestingController);
});

it('should be created', () => {
expect(service).toBeTruthy();
});

beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(AssignmentService);
});
it('should list assignments', () => {
service.list().subscribe((result) => {
expect(result).toEqual([mockEntity]);
});

const req = httpController.expectOne({
method: 'GET',
url: '/api/Assignment/List',
});

it('should be created', () => {
expect(service).toBeTruthy();
});
req.flush([mockEntity]);
httpController.verify();
});
});

0 comments on commit 970d5cf

Please sign in to comment.