From c8da7e995ff75e29960ee527b1926f7a9d04ce5a Mon Sep 17 00:00:00 2001 From: Marc Laval Date: Tue, 9 Aug 2016 16:20:57 +0200 Subject: [PATCH] test(router): Android browser does not support element.click() --- modules/@angular/router/test/router.spec.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/modules/@angular/router/test/router.spec.ts b/modules/@angular/router/test/router.spec.ts index 4b3a0e8431..e07003063f 100644 --- a/modules/@angular/router/test/router.spec.ts +++ b/modules/@angular/router/test/router.spec.ts @@ -11,6 +11,7 @@ import 'rxjs/add/operator/map'; import {Location} from '@angular/common'; import {Component, NgModule, NgModuleFactoryLoader} from '@angular/core'; import {ComponentFixture, TestBed, TestComponentBuilder, addProviders, fakeAsync, inject, tick} from '@angular/core/testing'; +import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; import {expect} from '@angular/platform-browser/testing/matchers'; import {Observable} from 'rxjs/Observable'; import {of } from 'rxjs/observable/of'; @@ -664,7 +665,7 @@ describe('Integration', () => { const native = fixture.debugElement.nativeElement.querySelector('a'); expect(native.getAttribute('href')).toEqual('/team/33/simple'); - native.click(); + dispatchClick(native); advance(fixture); expect(fixture.debugElement.nativeElement).toHaveText('team 33 [ simple, right: ]'); @@ -742,7 +743,7 @@ describe('Integration', () => { expect(fixture.debugElement.nativeElement).toHaveText('team 22 [ link, right: ]'); const native = fixture.debugElement.nativeElement.querySelector('button'); - native.click(); + dispatchClick(native); advance(fixture); expect(fixture.debugElement.nativeElement).toHaveText('team 33 [ simple, right: ]'); @@ -768,7 +769,7 @@ describe('Integration', () => { const native = fixture.debugElement.nativeElement.querySelector('a'); expect(native.getAttribute('href')).toEqual('/team/33/simple'); - native.click(); + dispatchClick(native); advance(fixture); expect(fixture.debugElement.nativeElement).toHaveText('team 33 [ simple, right: ]'); @@ -794,7 +795,7 @@ describe('Integration', () => { const native = fixture.debugElement.nativeElement.querySelector('a'); expect(native.getAttribute('href')).toEqual('/team/22/simple'); - native.click(); + dispatchClick(native); advance(fixture); expect(fixture.debugElement.nativeElement).toHaveText('team 22 [ simple, right: ]'); @@ -821,7 +822,7 @@ describe('Integration', () => { const native = fixture.debugElement.nativeElement.querySelector('a'); expect(native.getAttribute('href')).toEqual('/simple'); - native.click(); + dispatchClick(native); advance(fixture); expect(fixture.debugElement.nativeElement).toHaveText('link simple'); @@ -847,7 +848,7 @@ describe('Integration', () => { const native = fixture.debugElement.nativeElement.querySelector('a'); expect(native.getAttribute('href')).toEqual('/team/22/simple?q=1#f'); - native.click(); + dispatchClick(native); advance(fixture); expect(fixture.debugElement.nativeElement).toHaveText('team 22 [ simple, right: ]'); @@ -1804,3 +1805,8 @@ function createRoot(tcb: TestComponentBuilder, router: Router, type: any): Compo advance(f); return f; } + +function dispatchClick(target: HTMLElement): void { + const dispatchedEvent = getDOM().createMouseEvent('click'); + getDOM().dispatchEvent(target, dispatchedEvent); +}