Skip to content

Instantly share code, notes, and snippets.

@lydemann
Created July 9, 2018 06:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lydemann/1b5aa49208d14b6e21ff8209a5001861 to your computer and use it in GitHub Desktop.
Save lydemann/1b5aa49208d14b6e21ff8209a5001861 to your computer and use it in GitHub Desktop.
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