Skip to content

Instantly share code, notes, and snippets.

@brandonroberts
Last active March 2, 2017 17:11
Show Gist options
  • Save brandonroberts/a7faa171760aacbd7a53ec3d3342304c to your computer and use it in GitHub Desktop.
Save brandonroberts/a7faa171760aacbd7a53ec3d3342304c to your computer and use it in GitHub Desktop.
Collection Page Test
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { Store, StoreModule } from '@ngrx/store';
import { By } from '@angular/platform-browser';
import { DebugElement, NO_ERRORS_SCHEMA } from '@angular/core';
import * as fromRoot from '../reducers';
import * as collection from '../actions/collection';
import { ComponentsModule } from '../components';
import { CollectionPageComponent } from './collection-page';
describe('CollectionPageComponent', () => {
let component: CollectionPageComponent;
let fixture: ComponentFixture<CollectionPageComponent>;
let debugElement: DebugElement;
let store: Store<fromRoot.State>;
let books;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
ComponentsModule,
StoreModule.provideStore(fromRoot.reducer),
RouterTestingModule
],
declarations: [ CollectionPageComponent ],
schemas: [
NO_ERRORS_SCHEMA // ignore unknown elements
]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(CollectionPageComponent);
store = TestBed.get(Store);
component = fixture.componentInstance;
debugElement = fixture.debugElement;
fixture.detectChanges();
});
beforeEach(() => {
books = [
{
id: 'bookId',
volumeInfo: {
title: 'Title',
subtitle: 'subtitle',
authors: ['author'],
publisher: 'publisher',
publishDate: 'publishDate',
description: 'description',
averageRating: 5,
ratingsCount: 1,
imageLinks: {
thumbnail: '',
smallThumbnail: ''
}
}
}
];
});
it('should create an instance of CollectionPageComponent', () => {
expect(component).toBeTruthy();
});
it('should display loaded books', () => {
store.dispatch(new collection.LoadSuccessAction(books));
fixture.detectChanges();
const bookItems = debugElement.queryAll(By.css('bc-book-preview'));
expect(bookItems.length).toEqual(books.length);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment