import { TestBed, inject } from '@angular/core/testing'; | |
import { TodoListService } from './todo-list.service'; | |
import { HttpClient } from '@angular/common/http'; | |
import { TODOItem } from '../shared/models/todo-item'; | |
import { of } from 'rxjs/observable/of'; | |
describe('Service: TodoList', () => { | |
let todoListService: TodoListService; | |
const httpClientSpy: jasmine.SpyObj<HttpClient> = jasmine.createSpyObj('httpClient', ['get']); | |
httpClientSpy.get.and.returnValue(of([new TODOItem('Buy Milk', 'Lala')])); | |
beforeEach(() => { | |
TestBed.configureTestingModule({ | |
providers: [TodoListService, | |
{ | |
provide: HttpClient, | |
useValue: httpClientSpy | |
}] | |
}); | |
}); | |
beforeEach(inject([TodoListService], (service: TodoListService) => { | |
todoListService = service; | |
})); | |
it('should be defined', () => { | |
expect(todoListService).toBeTruthy(); | |
}); | |
it('should get todoList using http request', () => { | |
expect(httpClientSpy.get).toHaveBeenCalled(); | |
expect(todoListService.todoList.length).toBe(1); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment