Skip to content

Instantly share code, notes, and snippets.

@MatLang
Created June 19, 2019 10:32
Show Gist options
  • Save MatLang/2c0c55997d74570eebe3340f54a1f350 to your computer and use it in GitHub Desktop.
Save MatLang/2c0c55997d74570eebe3340f54a1f350 to your computer and use it in GitHub Desktop.
Dumb component testing #testing
describe('CoursesCardListComponent', () => {
let component: CoursesCardListComponent;
let fixture: ComponentFixture<CoursesCardListComponent>;
let el: DebugElement;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [CoursesModule]
})
.compileComponents()
.then(() => {
fixture = TestBed.createComponent(CoursesCardListComponent);
component = fixture.componentInstance;
el = fixture.debugElement;
});
}));
it('should create the component', () => {
expect(component).toBeTruthy();
});
it('should display the course list', () => {
component.courses = setupCourses();
fixture.detectChanges();
const cards = el.queryAll(By.css(".course-card"));
expect(cards).toBeTruthy("Could not find cards");
expect(cards.length).toBe(12, "Unexpected number of courses");
});
it('should display the first course', () => {
component.courses = setupCourses();
fixture.detectChanges();
const course = component.courses[0];
const card = el.query(By.css(".course-card:first-child")),
title = card.query(By.css("mat-card-title")),
image = card.query(By.css("img"));
expect(card).toBeTruthy("Could not find course card");
expect(title.nativeElement.textContent).toBe(course.titles.description);
expect(image.nativeElement.src).toBe(course.iconUrl);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment