Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit cd7b566

Browse files
committed
fix: karma shim values; update app.component.spec more like cli
1 parent e2d55c5 commit cd7b566

File tree

5 files changed

+25
-27
lines changed

5 files changed

+25
-27
lines changed

app/app.component.spec.ts

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,35 @@
11
/* tslint:disable:no-unused-variable */
22
import { AppComponent } from './app.component';
33

4-
import { TestBed } from '@angular/core/testing';
5-
4+
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
65
import { By } from '@angular/platform-browser';
6+
import { DebugElement } from '@angular/core';
77

88
//////// SPECS /////////////
9+
describe('AppComponent', function () {
10+
let de: DebugElement;
11+
let comp: AppComponent;
12+
let fixture: ComponentFixture<AppComponent>;
13+
14+
beforeEach(async(() => {
15+
TestBed.configureTestingModule({
16+
declarations: [ AppComponent ]
17+
})
18+
.compileComponents();
19+
}));
920

10-
/// Delete this
11-
describe('Smoke test', () => {
12-
it('should run a passing test', () => {
13-
expect(true).toEqual(true, 'should pass');
14-
});
15-
});
16-
17-
describe('AppComponent with TCB', function () {
1821
beforeEach(() => {
19-
TestBed.configureTestingModule({declarations: [AppComponent]});
22+
fixture = TestBed.createComponent(AppComponent);
23+
comp = fixture.componentInstance;
24+
de = fixture.debugElement.query(By.css('h1'));
2025
});
2126

22-
it('should instantiate component', () => {
23-
let fixture = TestBed.createComponent(AppComponent);
24-
expect(fixture.componentInstance instanceof AppComponent).toBe(true, 'should create AppComponent');
25-
});
27+
it('should create component', () => expect(comp).toBeDefined() );
2628

2729
it('should have expected <h1> text', () => {
28-
let fixture = TestBed.createComponent(AppComponent);
2930
fixture.detectChanges();
30-
31-
let h1 = fixture.debugElement.query(el => el.name === 'h1').nativeElement; // it works
32-
33-
h1 = fixture.debugElement.query(By.css('h1')).nativeElement; // preferred
34-
35-
expect(h1.innerText).toMatch(/angular app/i, '<h1> should say something about "Angular App"');
31+
const h1 = de.nativeElement;
32+
expect(h1.innerText).toMatch(/angular app/i,
33+
'<h1> should say something about "Angular App"');
3634
});
3735
});

app/app.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ import { Component } from '@angular/core';
22

33
@Component({
44
selector: 'my-app',
5-
template: '<h1>My First Angular App</h1>'
5+
template: `<h1>My First Angular App</h1>`
66
})
77
export class AppComponent { }

app/app.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { BrowserModule } from '@angular/platform-browser';
44
import { AppComponent } from './app.component';
55

66
@NgModule({
7-
imports: [ BrowserModule ],
7+
imports: [ BrowserModule ],
88
declarations: [ AppComponent ],
9-
bootstrap: [ AppComponent ]
9+
bootstrap: [ AppComponent ]
1010
})
1111
export class AppModule { }

karma-test-shim.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var allSpecFiles = Object.keys(window.__karma__.files)
2828
.filter(isBuiltFile);
2929

3030
System.config({
31-
baseURL: '/base',
31+
baseURL: 'base',
3232
// Extend usual application package list with test folder
3333
packages: { 'testing': { main: 'index.js', defaultExtension: 'js' } },
3434

karma.conf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module.exports = function(config) {
33

44
var appBase = 'app/'; // transpiled app JS and map files
55
var appSrcBase = 'app/'; // app source TS files
6-
var appAssets = '/base/app/'; // component assets fetched by Angular's compiler
6+
var appAssets = 'base/app/'; // component assets fetched by Angular's compiler
77

88
var testBase = 'testing/'; // transpiled test JS and map files
99
var testSrcBase = 'testing/'; // test source TS files

0 commit comments

Comments
 (0)