Skip to content

Commit

Permalink
test(linkTo): Refactored tests that triggered new windows on click ev…
Browse files Browse the repository at this point in the history
…ents
  • Loading branch information
brandonroberts authored and MikeRyanDev committed Apr 6, 2016
1 parent af160d7 commit 9f6eaf2
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions spec/link-to.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
injectAsync,
expect
} from 'angular2/testing';
import { Component, provide } from 'angular2/core';
import { Component, provide, ViewChild } from 'angular2/core';
import { LinkTo } from '../lib/link-to';
import { LOCATION_PROVIDERS, Location } from '../lib/location';
import { Observable } from 'rxjs/Observable';
Expand All @@ -20,7 +20,9 @@ import { MockLocationStrategy } from 'angular2/src/mock/mock_location_strategy';
template: '',
directives: [LinkTo]
})
class TestComponent{}
class TestComponent{
@ViewChild(LinkTo) link: LinkTo;
}

const compile = (tcb: TestComponentBuilder, template: string = '') => {
return tcb
Expand Down Expand Up @@ -102,7 +104,9 @@ describe('Link To', () => {

spyOn(location, 'go');

link.click();
let instance = fixture.componentInstance.link;
let event = { button: 1 };
instance.onClick(event);

expect(location.go).not.toHaveBeenCalled();
});
Expand All @@ -117,14 +121,28 @@ describe('Link To', () => {
fixture.detectChanges();
let compiled = fixture.debugElement.nativeElement;
let link: Element = compiled.querySelector('a');
fixture.detectChanges();

spyOn(location, 'go');

let event = new MouseEvent('click', { metaKey: true });
let instance = fixture.componentInstance.link;

compiled.dispatchEvent(event, link);
spyOn(location, 'go');

expect(location.go).not.toHaveBeenCalled();
let events = [
{ which: 1, ctrlKey: true },
{ which: 1, metaKey: true },
{ which: 1, shiftKey: true },
{ which: 2 },
{ button: 2 },
{ ctrlKey: true },
{ metaKey: true },
{ shiftKey: true }
];

events.forEach((event) => {
instance.onClick(event);
});

expect(location.go.calls.count()).toEqual(0);
});
}));
});
Expand Down

0 comments on commit 9f6eaf2

Please sign in to comment.