import { Router } from '@angular/router'; /* tslint:disable:no-unused-variable */ import { TestBed, async, ComponentFixture } from '@angular/core/testing'; import { AppComponent } from './app.component'; import { MaterialModule } from '@angular/material'; import { AppRoutingModule } from './app-routing.module'; import { APP_BASE_HREF } from '@angular/common'; import { RouterLinkStubDirective, RouterOutletStubComponent } from '../testing/router-stubs'; import { AppConfig } from './app-config.interface'; import { APP_CONFIG } from './app-config'; import { UserService } from './auth/user.service'; import 'hammerjs'; describe('AppComponent', () => { let fixture: ComponentFixture; beforeEach(() => { const TEST_CONFIG: AppConfig = { apiEndpoint: null, title: 'Byteflies' }; const user = { auth: false, login: () => this.auth = true, logout: () => this.auth = false, loggedIn: () => this.auth }; TestBed.configureTestingModule({ imports: [ MaterialModule.forRoot() ], providers: [ { provide: APP_CONFIG, useValue: TEST_CONFIG }, { provide: UserService, useValue: user }, { provide: Router, useValue: { navigate: jasmine.createSpy('navigate') } } ], declarations: [ AppComponent, RouterLinkStubDirective, RouterOutletStubComponent ], }); TestBed.compileComponents(); fixture = TestBed.createComponent(AppComponent); }); it('should create the app', async(() => { const app = fixture.debugElement.componentInstance; expect(app).toBeTruthy(); })); it(`should have as title 'Byteflies'`, async(() => { const app = fixture.debugElement.componentInstance; expect(app.title).toBe('Byteflies'); })); it('should render title in a h1 tag', async(() => { fixture.detectChanges(); const compiled = fixture.debugElement.nativeElement; expect(compiled.querySelector('h1').textContent).toContain('Byteflies'); })); it('should have links in it\'s nav element', async(() => { fixture.detectChanges(); const compiled = fixture.debugElement.nativeElement; expect(compiled.querySelectorAll('nav a').length).toBeGreaterThan(0); })); });