Skip to content

Commit

Permalink
fix(routes): fix providers for route unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
filipesilva committed Feb 12, 2016
1 parent fcdd82d commit ecd2cf1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,30 @@ import {
TestComponentBuilder,
beforeEachProviders
} from 'angular2/testing';
import {provide} from 'angular2/core';
import {bind} from 'angular2/core';
import {<%= classifiedModuleName %>DetailComponent} from './<%= dasherizedModuleName %>-detail.component';
import {Router, RouteParams} from 'angular2/router';
import {<%= classifiedModuleName %>, <%= classifiedModuleName %>Service} from './<%= dasherizedModuleName %>.service';

class Mock<%= classifiedModuleName %>Service {
get() { return Promise.resolve(new <%= classifiedModuleName %>(1, 'one')); }
}

class MockRouter {
navigate() { }
}

class MockRouteParams {
get() { return 1; }
}

describe('<%= classifiedModuleName %>DetailComponent', () => {

beforeEachProviders(() => []);
beforeEachProviders(() => [
bind(<%= classifiedModuleName %>Service).toValue(new Mock<%= classifiedModuleName %>Service()),
bind(Router).toValue(new MockRouter()),
bind(RouteParams).toValue(new MockRouteParams()),
]);

it('should ...', injectAsync([TestComponentBuilder], (tcb:TestComponentBuilder) => {
return tcb.createAsync(<%= classifiedModuleName %>DetailComponent).then((fixture) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,19 @@ import {
TestComponentBuilder,
beforeEachProviders
} from 'angular2/testing';
import {provide} from 'angular2/core';
import {bind} from 'angular2/core';
import {<%= classifiedModuleName %>ListComponent} from './<%= dasherizedModuleName %>-list.component';
import {<%= classifiedModuleName %>, <%= classifiedModuleName %>Service} from './<%= dasherizedModuleName %>.service';

class Mock<%= classifiedModuleName %>Service {
getAll() { return Promise.resolve([new <%= classifiedModuleName %>(1, 'one')]); }
}

describe('<%= classifiedModuleName %>ListComponent', () => {

beforeEachProviders(() => []);
beforeEachProviders(() => [
bind(<%= classifiedModuleName %>Service).toValue(new Mock<%= classifiedModuleName %>Service()),
]);

it('should ...', injectAsync([TestComponentBuilder], (tcb:TestComponentBuilder) => {
return tcb.createAsync(<%= classifiedModuleName %>ListComponent).then((fixture) => {
Expand Down

0 comments on commit ecd2cf1

Please sign in to comment.