Skip to content

Commit

Permalink
fix: karma shim values; update app.component.spec more like cli
Browse files Browse the repository at this point in the history
  • Loading branch information
wardbell committed Oct 30, 2016
1 parent e2d55c5 commit cd7b566
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 27 deletions.
42 changes: 20 additions & 22 deletions app/app.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,35 @@
/* tslint:disable:no-unused-variable */
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 { DebugElement } from '@angular/core';

//////// 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(() => {
TestBed.configureTestingModule({declarations: [AppComponent]});
fixture = TestBed.createComponent(AppComponent);
comp = fixture.componentInstance;
de = fixture.debugElement.query(By.css('h1'));
});

it('should instantiate component', () => {
let fixture = TestBed.createComponent(AppComponent);
expect(fixture.componentInstance instanceof AppComponent).toBe(true, 'should create AppComponent');
});
it('should create component', () => expect(comp).toBeDefined() );

it('should have expected <h1> text', () => {
let fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();

let h1 = fixture.debugElement.query(el => el.name === 'h1').nativeElement; // it works

h1 = fixture.debugElement.query(By.css('h1')).nativeElement; // preferred

expect(h1.innerText).toMatch(/angular app/i, '<h1> should say something about "Angular App"');
const h1 = de.nativeElement;
expect(h1.innerText).toMatch(/angular app/i,
'<h1> should say something about "Angular App"');
});
});
2 changes: 1 addition & 1 deletion app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import { Component } from '@angular/core';

@Component({
selector: 'my-app',
template: '<h1>My First Angular App</h1>'
template: `<h1>My First Angular App</h1>`
})
export class AppComponent { }
4 changes: 2 additions & 2 deletions app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';

@NgModule({
imports: [ BrowserModule ],
imports: [ BrowserModule ],
declarations: [ AppComponent ],
bootstrap: [ AppComponent ]
bootstrap: [ AppComponent ]
})
export class AppModule { }
2 changes: 1 addition & 1 deletion karma-test-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var allSpecFiles = Object.keys(window.__karma__.files)
.filter(isBuiltFile);

System.config({
baseURL: '/base',
baseURL: 'base',
// Extend usual application package list with test folder
packages: { 'testing': { main: 'index.js', defaultExtension: 'js' } },

Expand Down
2 changes: 1 addition & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module.exports = function(config) {

var appBase = 'app/'; // transpiled app JS and map 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 testSrcBase = 'testing/'; // test source TS files
Expand Down

0 comments on commit cd7b566

Please sign in to comment.