blob: 520b6136fbc081f4de062328a21f68b6c64c57e3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { TodoItemComponent } from './todo-item.component';
import { TodoItem } from '../todo-list-page/todo-list.service';
import { By } from '@angular/platform-browser';
import { NO_ERRORS_SCHEMA } from '@angular/core';
describe('TodoItemComponent', () => {
let component: TodoItemComponent;
let fixture: ComponentFixture<TodoItemComponent>;
const mockTodoItem: TodoItem = {
number: 1,
title: 'Title',
isClosed: true,
detailUrl: '/detail',
};
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [TodoItemComponent],
schemas: [NO_ERRORS_SCHEMA]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(TodoItemComponent);
component = fixture.componentInstance;
component.item = mockTodoItem;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should set title', () => {
expect((fixture.debugElement.query(By.css('span.item-title')).nativeElement as HTMLSpanElement).textContent).toBe(
mockTodoItem.number + '. ' + mockTodoItem.title
);
});
it('should set detail link', () => {
expect(fixture.debugElement.query(By.css('a.item-detail-button')).properties['href']).toBe(mockTodoItem.detailUrl);
});
});
|