import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; import { Component, DebugElement, ElementRef } from '@angular/core'; import { Location } from '@angular/common'; import { BehaviorSubject } from 'rxjs/BehaviorSubject'; import { DeviceService } from 'app/shared/device.service'; import { LiveExampleComponent, EmbeddedPlunkerComponent } from './live-example.component'; const defaultTestPath = '/test'; describe('LiveExampleComponent', () => { let hostComponent: HostComponent; let liveExampleDe: DebugElement; let liveExampleComponent: LiveExampleComponent; let fixture: ComponentFixture; let testPath: string; let liveExampleContent: string; //////// test helpers //////// class TestDeviceService { displayWidth = new BehaviorSubject(1001); } class TestMobileDeviceService { // 1000 is the trigger width for "narrow mobile device"" displayWidth = new BehaviorSubject(999); } @Component({ selector: 'aio-host-comp', template: `` }) class HostComponent { } class TestLocation { path() { return testPath; } } function getAnchors() { return liveExampleDe.queryAll(By.css('a')).map(de => de.nativeElement as HTMLAnchorElement); } function getHrefs() { return getAnchors().map(a => a.href); } function setHostTemplate(template: string) { TestBed.overrideComponent(HostComponent, {set: {template}}); } function testComponent(testFn: () => void) { return TestBed .compileComponents() .then(() => { fixture = TestBed.createComponent(HostComponent); hostComponent = fixture.componentInstance; liveExampleDe = fixture.debugElement.children[0]; liveExampleComponent = liveExampleDe.componentInstance; // Copy the LiveExample's innerHTML (content) // into the `liveExampleContent` property as the DocViewer does liveExampleDe.nativeElement.liveExampleContent = liveExampleContent; fixture.detectChanges(); }) .then(testFn); } //////// tests //////// beforeEach(() => { TestBed.configureTestingModule({ declarations: [ HostComponent, LiveExampleComponent, EmbeddedPlunkerComponent ], providers: [ { provide: DeviceService, useClass: TestDeviceService }, { provide: Location, useClass: TestLocation } ] }) // Disable the