Commit d8b3ba7e authored by Jesús Rodríguez's avatar Jesús Rodríguez Committed by GitHub

chore: update specs to TestBed (#184)

parent 6ce71a08
/* 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 /////////////
......@@ -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"');
});
});
......@@ -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);
......@@ -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 },
......
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