|
| 1 | +import { |
| 2 | + AsyncTestCompleter, |
| 3 | + beforeEach, |
| 4 | + ddescribe, |
| 5 | + describe, |
| 6 | + expect, |
| 7 | + iit, |
| 8 | + inject, |
| 9 | + it, |
| 10 | + xdescribe, |
| 11 | + xit, |
| 12 | + } from 'angular2/test_lib'; |
| 13 | + |
| 14 | +import {bootstrap} from 'angular2/src/core/application'; |
| 15 | +import {Component, Directive} from 'angular2/src/core/annotations_impl/annotations'; |
| 16 | +import {DOM} from 'angular2/src/dom/dom_adapter'; |
| 17 | +import {bind} from 'angular2/di'; |
| 18 | +import {View} from 'angular2/src/core/annotations_impl/view'; |
| 19 | +import {DOCUMENT_TOKEN} from 'angular2/src/render/dom/dom_renderer'; |
| 20 | +import {RouteConfig} from 'angular2/src/router/route_config_impl'; |
| 21 | +import {routerInjectables, Router, RouteParams, RouterOutlet} from 'angular2/router'; |
| 22 | +import {SpyLocation} from 'angular2/src/mock/location_mock'; |
| 23 | +import {Location} from 'angular2/src/router/location'; |
| 24 | + |
| 25 | +export function main() { |
| 26 | + describe('router injectables', () => { |
| 27 | + var fakeDoc, el, testBindings; |
| 28 | + beforeEach(() => { |
| 29 | + fakeDoc = DOM.createHtmlDocument(); |
| 30 | + el = DOM.createElement('app-cmp', fakeDoc); |
| 31 | + DOM.appendChild(fakeDoc.body, el); |
| 32 | + testBindings = [ |
| 33 | + routerInjectables, |
| 34 | + bind(Location).toClass(SpyLocation), |
| 35 | + bind(DOCUMENT_TOKEN).toValue(fakeDoc) |
| 36 | + ]; |
| 37 | + }); |
| 38 | + |
| 39 | + it('should support bootstrap a simple app', inject([AsyncTestCompleter], (async) => { |
| 40 | + bootstrap(AppCmp, testBindings).then((applicationRef) => { |
| 41 | + var router = applicationRef.hostComponent.router; |
| 42 | + router.subscribe((_) => { |
| 43 | + expect(el).toHaveText('outer { hello }'); |
| 44 | + async.done(); |
| 45 | + }); |
| 46 | + }); |
| 47 | + })); |
| 48 | + |
| 49 | + //TODO: add a test in which the child component has bindings |
| 50 | + }); |
| 51 | +} |
| 52 | + |
| 53 | + |
| 54 | +@Component({ |
| 55 | + selector: 'hello-cmp' |
| 56 | +}) |
| 57 | +@View({ |
| 58 | + template: "hello" |
| 59 | +}) |
| 60 | +class HelloCmp {} |
| 61 | + |
| 62 | + |
| 63 | +@Component({ |
| 64 | + selector: 'app-cmp' |
| 65 | +}) |
| 66 | +@View({ |
| 67 | + template: "outer { <router-outlet></router-outlet> }", |
| 68 | + directives: [RouterOutlet] |
| 69 | +}) |
| 70 | +@RouteConfig([{ |
| 71 | + path: '/', component: HelloCmp |
| 72 | +}]) |
| 73 | +class AppCmp { |
| 74 | + router:Router; |
| 75 | + constructor(router:Router) { |
| 76 | + this.router = router; |
| 77 | + } |
| 78 | +} |
0 commit comments