|
| 1 | +import {ComponentFixture, getTestBed, TestBed} from '@angular/core/testing'; |
| 2 | +import {FormsModule, ReactiveFormsModule} from '@angular/forms'; |
| 3 | +import {BrowserAnimationsModule} from '@angular/platform-browser/animations'; |
| 4 | + |
| 5 | +import {MaterialModule} from '../../modules'; |
| 6 | +import {TodoService} from '../../services/todo/todo.service'; |
| 7 | +import {InputComponent} from '../input/input.component'; |
| 8 | +import {TodoListComponent} from '../todo-list/todo-list.component'; |
| 9 | + |
| 10 | +import {AppComponent} from './app.component'; |
| 11 | + |
| 12 | +describe('AppComponent', () => { |
| 13 | +let component: AppComponent; |
| 14 | +let fixture: ComponentFixture<AppComponent>; |
| 15 | + |
| 16 | +let todoService: TodoService; |
| 17 | + |
| 18 | +beforeEach(() => { |
| 19 | +TestBed.configureTestingModule({ |
| 20 | +declarations: [AppComponent, InputComponent, TodoListComponent], |
| 21 | +imports: [MaterialModule, FormsModule, ReactiveFormsModule, BrowserAnimationsModule] |
| 22 | +}); |
| 23 | + |
| 24 | +fixture = TestBed.createComponent(AppComponent); |
| 25 | +component = fixture.componentInstance; |
| 26 | + |
| 27 | +todoService = getTestBed().get(TodoService); |
| 28 | + |
| 29 | +fixture.detectChanges(); |
| 30 | +}); |
| 31 | + |
| 32 | +it('should create the app', () => { |
| 33 | +expect(component).toBeTruthy(); |
| 34 | +}); |
| 35 | + |
| 36 | +describe('addItem', () => { |
| 37 | +it('should call addTodo of TodoService', () => { |
| 38 | +const text: string = 'SomeText'; |
| 39 | +const spy = spyOn(todoService, 'addTodo'); |
| 40 | + |
| 41 | +component.addItem(text); |
| 42 | + |
| 43 | +expect(spy).toHaveBeenCalled(); |
| 44 | +expect(spy).toHaveBeenCalledWith({text}); |
| 45 | +}); |
| 46 | + |
| 47 | +it('should call getTodos of TodoService', () => { |
| 48 | +const text: string = 'SomeText'; |
| 49 | +const spy = spyOn(todoService, 'getTodos'); |
| 50 | + |
| 51 | +component.addItem(text); |
| 52 | + |
| 53 | +expect(spy).toHaveBeenCalled(); |
| 54 | +}); |
| 55 | +}); |
| 56 | + |
| 57 | +describe('getTodos', () => { |
| 58 | +it('should call getTodos of TodoService', () => { |
| 59 | +const spy = spyOn(todoService, 'getTodos'); |
| 60 | + |
| 61 | +component.getTodos(); |
| 62 | + |
| 63 | +expect(spy).toHaveBeenCalled(); |
| 64 | +}); |
| 65 | +}); |
| 66 | +}); |
0 commit comments