Fix unit tests

This commit is contained in:
Cameron Cordes
2020-03-06 20:30:01 -05:00
parent d15a9c06f4
commit 17c97302fe
2 changed files with 21 additions and 2 deletions

View File

@@ -1,13 +1,19 @@
import {async, TestBed} from '@angular/core/testing'; import {async, TestBed} from '@angular/core/testing';
import { InjectionToken } from "@angular/core";
import {AppComponent} from './app.component'; import {AppComponent} from './app.component';
import {ToolbarComponent} from "./toolbar/toolbar.component"; import {ToolbarComponent} from "./toolbar/toolbar.component";
import {RouterTestingModule} from "@angular/router/testing"; import {RouterTestingModule} from "@angular/router/testing";
import { MatSidenavModule } from "@angular/material/sidenav"; import { MatSidenavModule } from "@angular/material/sidenav";
import { MatToolbarModule } from "@angular/material/toolbar"; import { MatToolbarModule } from "@angular/material/toolbar";
import {NoopAnimationsModule} from "@angular/platform-browser/animations"; import {NoopAnimationsModule} from "@angular/platform-browser/animations";
import { RouterlessTracking } from "angulartics2";
import { Angulartics2Piwik } from "angulartics2/piwik";
describe('AppComponent', () => { describe('AppComponent', () => {
let piwik: Angulartics2Piwik;
beforeEach(async(() => { beforeEach(async(() => {
piwik = jasmine.createSpyObj('piwik', ['startTracking']);
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [ imports: [
RouterTestingModule, RouterTestingModule,
@@ -19,11 +25,23 @@ describe('AppComponent', () => {
AppComponent, AppComponent,
ToolbarComponent ToolbarComponent
], ],
providers: [
{ provide: Angulartics2Piwik, useValue: piwik },
],
}).compileComponents(); }).compileComponents();
})); }));
it('should create the app', async(() => { it('should create the app', async(() => {
const fixture = TestBed.createComponent(AppComponent); const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance; const app = fixture.debugElement.componentInstance;
expect(app).toBeTruthy(); expect(app).toBeTruthy();
})); }));
it('should call start tracking once loaded', () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
expect(piwik.startTracking).toHaveBeenCalled();
});
}); });

View File

@@ -41,8 +41,9 @@ describe('ToolbarComponent', () => {
it('should contain 4 links, Home, Resume, Projects, Contact', () => { it('should contain 4 links, Home, Resume, Projects, Contact', () => {
let debugElements = fixture.debugElement.queryAll((element) => { let debugElements = fixture.debugElement.queryAll((element) => {
return element.nativeElement.class == 'span' return element.nativeElement.className.indexOf("mat-toolbar") != -1;
}); });
expect(debugElements[0].nativeElement).toBe("span");
expect(debugElements[0].children.length).toBe(4);
}); });
}); });