Skip to content

Commit

Permalink
update tests for RC4
Browse files Browse the repository at this point in the history
  • Loading branch information
rascada authored and Foxandxss committed Jul 8, 2016
1 parent adc2a61 commit 6b4a5c6
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 34 deletions.
9 changes: 4 additions & 5 deletions src/app/about/about.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import {
it,
describe,
async,
inject,
beforeEachProviders
addProviders
} from '@angular/core/testing';

import { TestComponentBuilder } from '@angular/compiler/testing';

import { AboutComponent } from './about.component';

describe('About Component', () => {

beforeEachProviders(() => []);
beforeEach(() => {
addProviders([]);
});

it('should ...', async(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
tcb.createAsync(AboutComponent).then((fixture) => {
Expand Down
33 changes: 17 additions & 16 deletions src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
import {
it,
inject,
beforeEachProviders
addProviders
} from '@angular/core/testing';

// to use Translate Service, we need Http, and to test Http we need to mock the backend
import { BaseRequestOptions, Http } from '@angular/http';
import { MockBackend } from '@angular/http/testing';
import { provide } from '@angular/core';

// Load the implementations that should be tested
import { ApiService } from './shared';
import { AppComponent } from './app.component';

describe('App', () => {
// provide our implementations or mocks to the dependency injector
beforeEachProviders(() => [
AppComponent,
ApiService,
BaseRequestOptions,
MockBackend,
// Provide a mocked (fake) backend for Http
provide(Http, {
useFactory: function useFactory(backend, defaultOptions) {
return new Http(backend, defaultOptions);
},
deps: [MockBackend, BaseRequestOptions]
})
]);
beforeEach(() => {
addProviders([
AppComponent,
ApiService,
BaseRequestOptions,
MockBackend,
// Provide a mocked (fake) backend for Http
{
provide: Http,
deps: [MockBackend, BaseRequestOptions],
useFactory: function useFactory(backend, defaultOptions) {
return new Http(backend, defaultOptions);
}
}
]);
});

it('should have an url', inject([AppComponent], (app: AppComponent) => {
expect(app.url).toEqual('https://github.com/preboot/angular2-webpack');
Expand Down
10 changes: 4 additions & 6 deletions src/app/home/home.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import {
it,
inject,
describe,
beforeEachProviders,
addProviders,
} from '@angular/core/testing';

// Load the implementations that should be tested
import { HomeComponent } from './home.component';

describe('Home', () => {
// provide our implementations or mocks to the dependency injector
beforeEachProviders(() => [
HomeComponent
]);
beforeEach(() => {
addProviders([HomeComponent]);
});

it('should log ngOnInit', inject([HomeComponent], (home) => {
spyOn(console, 'log');
Expand Down
11 changes: 4 additions & 7 deletions src/app/shared/api.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import {
it,
describe,
expect,
inject,
beforeEachProviders
addProviders
} from '@angular/core/testing';

import { ApiService } from './api.service';

describe('Api Service', () => {

beforeEachProviders(() => [ApiService]);
beforeEach(() => {
addProviders([ApiService]);
});

it('should ...', inject([ApiService], (api: ApiService) => {
expect(api.title).toBe('Angular 2');
}));

});

0 comments on commit 6b4a5c6

Please sign in to comment.