test(router): refactor integration tests to use TestComponentBuilder
Closes #3182
This commit is contained in:
parent
c3d61bc63c
commit
476988876c
|
@ -1,6 +1,7 @@
|
||||||
import {
|
import {
|
||||||
AsyncTestCompleter,
|
AsyncTestCompleter,
|
||||||
beforeEach,
|
beforeEach,
|
||||||
|
beforeEachBindings,
|
||||||
ddescribe,
|
ddescribe,
|
||||||
describe,
|
describe,
|
||||||
expect,
|
expect,
|
||||||
|
@ -8,6 +9,7 @@ import {
|
||||||
inject,
|
inject,
|
||||||
it,
|
it,
|
||||||
xdescribe,
|
xdescribe,
|
||||||
|
TestComponentBuilder,
|
||||||
xit,
|
xit,
|
||||||
} from 'angular2/test_lib';
|
} from 'angular2/test_lib';
|
||||||
|
|
||||||
|
@ -22,73 +24,93 @@ import {BaseException} from 'angular2/src/facade/lang';
|
||||||
import {routerInjectables, Router, appBaseHrefToken, routerDirectives} from 'angular2/router';
|
import {routerInjectables, Router, appBaseHrefToken, routerDirectives} from 'angular2/router';
|
||||||
import {LocationStrategy} from 'angular2/src/router/location_strategy';
|
import {LocationStrategy} from 'angular2/src/router/location_strategy';
|
||||||
import {MockLocationStrategy} from 'angular2/src/mock/mock_location_strategy';
|
import {MockLocationStrategy} from 'angular2/src/mock/mock_location_strategy';
|
||||||
|
import {appComponentTypeToken} from 'angular2/src/core/application_tokens';
|
||||||
|
|
||||||
export function main() {
|
export function main() {
|
||||||
describe('router injectables', () => {
|
describe('router injectables', () => {
|
||||||
var fakeDoc, el, testBindings;
|
beforeEachBindings(() => {
|
||||||
beforeEach(() => {
|
return [routerInjectables, bind(LocationStrategy).toClass(MockLocationStrategy)];
|
||||||
fakeDoc = DOM.createHtmlDocument();
|
|
||||||
el = DOM.createElement('app-cmp', fakeDoc);
|
|
||||||
DOM.appendChild(fakeDoc.body, el);
|
|
||||||
testBindings = [
|
|
||||||
routerInjectables,
|
|
||||||
bind(LocationStrategy).toClass(MockLocationStrategy),
|
|
||||||
bind(DOCUMENT_TOKEN).toValue(fakeDoc)
|
|
||||||
];
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should bootstrap a simple app', inject([AsyncTestCompleter], (async) => {
|
// do not refactor out the `bootstrap` functionality. We still want to
|
||||||
bootstrap(AppCmp, testBindings)
|
// keep this test around so we can ensure that bootstrapping a router works
|
||||||
.then((applicationRef) => {
|
describe('boostrap functionality', () => {
|
||||||
var router = applicationRef.hostComponent.router;
|
it('should bootstrap a simple app', inject([AsyncTestCompleter], (async) => {
|
||||||
router.subscribe((_) => {
|
var fakeDoc = DOM.createHtmlDocument();
|
||||||
expect(el).toHaveText('outer { hello }');
|
var el = DOM.createElement('app-cmp', fakeDoc);
|
||||||
expect(applicationRef.hostComponent.location.path()).toEqual('');
|
DOM.appendChild(fakeDoc.body, el);
|
||||||
async.done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should rethrow exceptions from component constructors',
|
bootstrap(AppCmp,
|
||||||
inject([AsyncTestCompleter], (async) => {
|
[
|
||||||
bootstrap(BrokenAppCmp, testBindings)
|
routerInjectables,
|
||||||
.then((applicationRef) => {
|
bind(LocationStrategy).toClass(MockLocationStrategy),
|
||||||
var router = applicationRef.hostComponent.router;
|
bind(DOCUMENT_TOKEN).toValue(fakeDoc)
|
||||||
PromiseWrapper.catchError(router.navigate('/cause-error'), (error) => {
|
])
|
||||||
expect(el).toHaveText('outer { oh no }');
|
.then((applicationRef) => {
|
||||||
expect(error.message).toContain('oops!');
|
var router = applicationRef.hostComponent.router;
|
||||||
async.done();
|
router.subscribe((_) => {
|
||||||
|
expect(el).toHaveText('outer { hello }');
|
||||||
|
expect(applicationRef.hostComponent.location.path()).toEqual('');
|
||||||
|
async.done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
}));
|
||||||
}));
|
});
|
||||||
|
|
||||||
it('should bootstrap an app with a hierarchy', inject([AsyncTestCompleter], (async) => {
|
describe('broken app', () => {
|
||||||
bootstrap(HierarchyAppCmp, testBindings)
|
beforeEachBindings(() => { return [bind(appComponentTypeToken).toValue(BrokenAppCmp)]; });
|
||||||
.then((applicationRef) => {
|
|
||||||
var router = applicationRef.hostComponent.router;
|
|
||||||
router.subscribe((_) => {
|
|
||||||
expect(el).toHaveText('root { parent { hello } }');
|
|
||||||
expect(applicationRef.hostComponent.location.path()).toEqual('/parent/child');
|
|
||||||
async.done();
|
|
||||||
});
|
|
||||||
router.navigate('/parent/child');
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should bootstrap an app with a custom app base href',
|
it('should rethrow exceptions from component constructors',
|
||||||
inject([AsyncTestCompleter], (async) => {
|
inject([AsyncTestCompleter, TestComponentBuilder], (async, tcb: TestComponentBuilder) => {
|
||||||
bootstrap(HierarchyAppCmp, [testBindings, bind(appBaseHrefToken).toValue('/my/app')])
|
tcb.createAsync(AppCmp).then((rootTC) => {
|
||||||
.then((applicationRef) => {
|
var router = rootTC.componentInstance.router;
|
||||||
var router = applicationRef.hostComponent.router;
|
PromiseWrapper.catchError(router.navigate('/cause-error'), (error) => {
|
||||||
router.subscribe((_) => {
|
expect(rootTC.nativeElement).toHaveText('outer { oh no }');
|
||||||
expect(el).toHaveText('root { parent { hello } }');
|
expect(error.message).toContain('oops!');
|
||||||
expect(applicationRef.hostComponent.location.path())
|
async.done();
|
||||||
.toEqual('/my/app/parent/child');
|
|
||||||
async.done();
|
|
||||||
});
|
|
||||||
router.navigate('/parent/child');
|
|
||||||
});
|
});
|
||||||
}));
|
});
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('hierarchical app', () => {
|
||||||
|
beforeEachBindings(() => { return [bind(appComponentTypeToken).toValue(HierarchyAppCmp)]; });
|
||||||
|
|
||||||
|
it('should bootstrap an app with a hierarchy',
|
||||||
|
inject([AsyncTestCompleter, TestComponentBuilder], (async, tcb: TestComponentBuilder) => {
|
||||||
|
|
||||||
|
tcb.createAsync(HierarchyAppCmp)
|
||||||
|
.then((rootTC) => {
|
||||||
|
var router = rootTC.componentInstance.router;
|
||||||
|
router.subscribe((_) => {
|
||||||
|
expect(rootTC.nativeElement).toHaveText('root { parent { hello } }');
|
||||||
|
expect(rootTC.componentInstance.location.path()).toEqual('/parent/child');
|
||||||
|
async.done();
|
||||||
|
});
|
||||||
|
router.navigate('/parent/child');
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
|
||||||
|
describe('custom app base ref', () => {
|
||||||
|
beforeEachBindings(() => { return [bind(appBaseHrefToken).toValue('/my/app')]; });
|
||||||
|
it('should bootstrap', inject([AsyncTestCompleter, TestComponentBuilder],
|
||||||
|
(async, tcb: TestComponentBuilder) => {
|
||||||
|
|
||||||
|
tcb.createAsync(HierarchyAppCmp)
|
||||||
|
.then((rootTC) => {
|
||||||
|
var router = rootTC.componentInstance.router;
|
||||||
|
router.subscribe((_) => {
|
||||||
|
expect(rootTC.nativeElement)
|
||||||
|
.toHaveText('root { parent { hello } }');
|
||||||
|
expect(rootTC.componentInstance.location.path())
|
||||||
|
.toEqual('/my/app/parent/child');
|
||||||
|
async.done();
|
||||||
|
});
|
||||||
|
router.navigate('/parent/child');
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
});
|
||||||
// TODO: add a test in which the child component has bindings
|
// TODO: add a test in which the child component has bindings
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue