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

chore: update specs to TestBed #184

Merged
merged 1 commit into from
Aug 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 15 additions & 23 deletions app/app.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
/* tslint:disable:no-unused-variable */
import { AppComponent } from './app.component';

import { async, inject } from '@angular/core/testing';

import { TestComponentBuilder } from '@angular/core/testing';
import { TestBed } from '@angular/core/testing';

import { By } from '@angular/platform-browser';
import { provide } from '@angular/core';
import { ViewMetadata } from '@angular/core';

//////// SPECS /////////////

Expand All @@ -19,27 +15,23 @@ describe('Smoke test', () => {
});

describe('AppComponent with TCB', function () {
beforeEach(() => {
TestBed.configureTestingModule({declarations: [AppComponent]});
});

it('should instantiate component',
async(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {

tcb.createAsync(AppComponent).then(fixture => {
expect(fixture.componentInstance instanceof AppComponent).toBe(true, 'should create AppComponent');
});
})));

it('should have expected <h1> text',
async(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {

tcb.createAsync(AppComponent).then(fixture => {
// fixture.detectChanges(); // would need to resolve a binding but we don't have a binding
it('should instantiate component', () => {
let fixture = TestBed.createComponent(AppComponent);
expect(fixture.componentInstance instanceof AppComponent).toBe(true, 'should create AppComponent');
});

let h1 = fixture.debugElement.query(el => el.name === 'h1').nativeElement; // it works
it('should have expected <h1> text', () => {
let fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();

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

expect(h1.innerText).toMatch(/angular 2 app/i, '<h1> should say something about "Angular 2 App"');
});
h1 = fixture.debugElement.query(By.css('h1')).nativeElement; // preferred

})));
expect(h1.innerText).toMatch(/angular 2 app/i, '<h1> should say something about "Angular 2 App"');
});
});
33 changes: 15 additions & 18 deletions karma-test-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,24 @@ System.config({
});

System.import('systemjs.config.js')
.then(function () {
return Promise.all([
.then(() => Promise.all([
System.import('@angular/core/testing'),
System.import('@angular/platform-browser-dynamic/testing')
])
})
.then(function (providers) {
var testing = providers[0];
var testingBrowser = providers[1];

testing.setBaseTestProviders(
testingBrowser.TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
testingBrowser.TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);
]))
.then((providers) => {
var coreTesting = providers[0];
var browserTesting = providers[1];
coreTesting.TestBed.initTestEnvironment(
browserTesting.BrowserDynamicTestingModule,
browserTesting.platformBrowserDynamicTesting());

})
.then(function() {
// Finally, load all spec files.
// This will run the tests directly.
return Promise.all(
allSpecFiles.map(function (moduleName) {
return System.import(moduleName);
}));
.then(function () {
// Finally, load all spec files.
// This will run the tests directly.
return Promise.all(
allSpecFiles.map(function (moduleName) {
return System.import(moduleName);
}));
})
.then(__karma__.start, __karma__.error);
3 changes: 2 additions & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ module.exports = function(config) {
// Reflect and Zone.js
'node_modules/reflect-metadata/Reflect.js',
'node_modules/zone.js/dist/zone.js',
'node_modules/zone.js/dist/jasmine-patch.js',
'node_modules/zone.js/dist/async-test.js',
'node_modules/zone.js/dist/fake-async-test.js',
'node_modules/zone.js/dist/sync-test.js',
'node_modules/zone.js/dist/proxy-zone.js',

// RxJs.
{ pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false },
Expand Down