diff --git a/modules/angular2/test/router/router_link_spec.ts b/modules/angular2/test/router/router_link_spec.ts new file mode 100644 index 0000000000..7a215df68b --- /dev/null +++ b/modules/angular2/test/router/router_link_spec.ts @@ -0,0 +1,106 @@ +import { + AsyncTestCompleter, + beforeEach, + ddescribe, + xdescribe, + describe, + dispatchEvent, + expect, + iit, + inject, + IS_DARTIUM, + beforeEachBindings, + it, + xit, + TestComponentBuilder, + proxy, + SpyObject, + By +} from 'angular2/test_lib'; + +import {IMPLEMENTS, print} from 'angular2/src/facade/lang'; + +import {bind, Component, View} from 'angular2/angular2'; + +import {Location, Router, RouterLink} from 'angular2/router'; + +import { + DOM +} from 'angular2/src/dom/dom_adapter' + + + export function + main() { + describe('router-link directive', function() { + + beforeEachBindings( + () => + [bind(Location).toValue(makeDummyLocation()), bind(Router).toValue(makeDummyRouter())]); + + + it('should update a[href] attribute', + inject([TestComponentBuilder, AsyncTestCompleter], (tcb, async) => { + + tcb.createAsync(TestComponent) + .then((testComponent) => { + testComponent.detectChanges(); + let anchorElement = testComponent.query(By.css('a')).nativeElement; + expect(DOM.getAttribute(anchorElement, 'href')).toEqual('/detail'); + async.done(); + }); + })); + + + it('should call router.navigate when a link is clicked', + inject([TestComponentBuilder, AsyncTestCompleter, Router], (tcb, async, router) => { + + tcb.createAsync(TestComponent) + .then((testComponent) => { + testComponent.detectChanges(); + // TODO: shouldn't this be just 'click' rather than '^click'? + testComponent.query(By.css('a')).triggerEventHandler('^click', {}); + expect(router.spy("navigate")).toHaveBeenCalledWith('/detail'); + async.done(); + }); + })); + }); +} + + +@Component({selector: 'test-component'}) +@View({ + template: ` +