Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { BrowserModule } from '@angular/platform-browser';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { TodoListComponent } from './todo-list.component';
import { TodoListService } from '../core/todo-list.service';
import { TODOItem } from '../shared/models/todo-item';
describe('TodoListComponent', () => {
let component: TodoListComponent;
let fixture: ComponentFixture<TodoListComponent>;
beforeEach(async(() => {
const todo1 = new TODOItem('Buy milk', 'Remember to buy milk');
todo1.completed = true;
const todoList = [
todo1,
new TODOItem('Buy flowers', 'Remember to buy flowers'),
];
TestBed.configureTestingModule({
declarations: [
TodoListComponent,
],
imports: [
BrowserModule,
],
providers: [
{
provide: TodoListService,
useValue: {todoList: todoList}
}
],
schemas: [NO_ERRORS_SCHEMA]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(TodoListComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should have two completed TODO item', () => {
expect(component.todoList.length).toBe(2);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.