-
-
Save lydemann/c672de7f596e4601ab730a9be0b08eab to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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