Commit cd7b566f authored by Ward Bell's avatar Ward Bell

fix: karma shim values; update app.component.spec more like cli

parent e2d55c59
/* tslint:disable:no-unused-variable */ /* tslint:disable:no-unused-variable */
import { AppComponent } from './app.component'; import { AppComponent } from './app.component';
import { TestBed } from '@angular/core/testing'; import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser'; import { By } from '@angular/platform-browser';
import { DebugElement } from '@angular/core';
//////// SPECS ///////////// //////// SPECS /////////////
describe('AppComponent', function () {
let de: DebugElement;
let comp: AppComponent;
let fixture: ComponentFixture<AppComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ AppComponent ]
})
.compileComponents();
}));
/// Delete this
describe('Smoke test', () => {
it('should run a passing test', () => {
expect(true).toEqual(true, 'should pass');
});
});
describe('AppComponent with TCB', function () {
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({declarations: [AppComponent]}); fixture = TestBed.createComponent(AppComponent);
comp = fixture.componentInstance;
de = fixture.debugElement.query(By.css('h1'));
}); });
it('should instantiate component', () => { it('should create component', () => expect(comp).toBeDefined() );
let fixture = TestBed.createComponent(AppComponent);
expect(fixture.componentInstance instanceof AppComponent).toBe(true, 'should create AppComponent');
});
it('should have expected <h1> text', () => { it('should have expected <h1> text', () => {
let fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges(); fixture.detectChanges();
const h1 = de.nativeElement;
let h1 = fixture.debugElement.query(el => el.name === 'h1').nativeElement; // it works expect(h1.innerText).toMatch(/angular app/i,
'<h1> should say something about "Angular App"');
h1 = fixture.debugElement.query(By.css('h1')).nativeElement; // preferred
expect(h1.innerText).toMatch(/angular app/i, '<h1> should say something about "Angular App"');
}); });
}); });
...@@ -2,6 +2,6 @@ import { Component } from '@angular/core'; ...@@ -2,6 +2,6 @@ import { Component } from '@angular/core';
@Component({ @Component({
selector: 'my-app', selector: 'my-app',
template: '<h1>My First Angular App</h1>' template: `<h1>My First Angular App</h1>`
}) })
export class AppComponent { } export class AppComponent { }
...@@ -4,8 +4,8 @@ import { BrowserModule } from '@angular/platform-browser'; ...@@ -4,8 +4,8 @@ import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component'; import { AppComponent } from './app.component';
@NgModule({ @NgModule({
imports: [ BrowserModule ], imports: [ BrowserModule ],
declarations: [ AppComponent ], declarations: [ AppComponent ],
bootstrap: [ AppComponent ] bootstrap: [ AppComponent ]
}) })
export class AppModule { } export class AppModule { }
...@@ -28,7 +28,7 @@ var allSpecFiles = Object.keys(window.__karma__.files) ...@@ -28,7 +28,7 @@ var allSpecFiles = Object.keys(window.__karma__.files)
.filter(isBuiltFile); .filter(isBuiltFile);
System.config({ System.config({
baseURL: '/base', baseURL: 'base',
// Extend usual application package list with test folder // Extend usual application package list with test folder
packages: { 'testing': { main: 'index.js', defaultExtension: 'js' } }, packages: { 'testing': { main: 'index.js', defaultExtension: 'js' } },
......
...@@ -3,7 +3,7 @@ module.exports = function(config) { ...@@ -3,7 +3,7 @@ module.exports = function(config) {
var appBase = 'app/'; // transpiled app JS and map files var appBase = 'app/'; // transpiled app JS and map files
var appSrcBase = 'app/'; // app source TS files var appSrcBase = 'app/'; // app source TS files
var appAssets = '/base/app/'; // component assets fetched by Angular's compiler var appAssets = 'base/app/'; // component assets fetched by Angular's compiler
var testBase = 'testing/'; // transpiled test JS and map files var testBase = 'testing/'; // transpiled test JS and map files
var testSrcBase = 'testing/'; // test source TS files var testSrcBase = 'testing/'; // test source TS files
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment