test(ivy): run router/upgrade tests with ivy on CI (#27410)
PR Close #27410
This commit is contained in:
parent
6552471c49
commit
0cf49c8de3
@ -7,6 +7,7 @@ ts_library(
|
|||||||
deps = [
|
deps = [
|
||||||
"//packages/common",
|
"//packages/common",
|
||||||
"//packages/core/testing",
|
"//packages/core/testing",
|
||||||
|
"//packages/private/testing",
|
||||||
"//packages/router",
|
"//packages/router",
|
||||||
"//packages/router/upgrade",
|
"//packages/router/upgrade",
|
||||||
"//packages/upgrade/static",
|
"//packages/upgrade/static",
|
||||||
@ -15,9 +16,6 @@ ts_library(
|
|||||||
|
|
||||||
ts_web_test_suite(
|
ts_web_test_suite(
|
||||||
name = "test_web",
|
name = "test_web",
|
||||||
tags = [
|
|
||||||
"fixme-ivy-aot",
|
|
||||||
],
|
|
||||||
deps = [
|
deps = [
|
||||||
":test_lib",
|
":test_lib",
|
||||||
],
|
],
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
import {Location} from '@angular/common';
|
import {Location} from '@angular/common';
|
||||||
import {TestBed} from '@angular/core/testing';
|
import {TestBed} from '@angular/core/testing';
|
||||||
|
import {fixmeIvy} from '@angular/private/testing';
|
||||||
import {Router} from '@angular/router';
|
import {Router} from '@angular/router';
|
||||||
import {setUpLocationSync} from '@angular/router/upgrade';
|
import {setUpLocationSync} from '@angular/router/upgrade';
|
||||||
import {UpgradeModule} from '@angular/upgrade/static';
|
import {UpgradeModule} from '@angular/upgrade/static';
|
||||||
@ -43,59 +44,63 @@ describe('setUpLocationSync', () => {
|
|||||||
`);
|
`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should get the $rootScope from AngularJS and set an $on watch on $locationChangeStart',
|
fixmeIvy('FW-777: R3Injector doesn\'t support injectors as a provider') &&
|
||||||
() => {
|
it('should get the $rootScope from AngularJS and set an $on watch on $locationChangeStart',
|
||||||
const $rootScope = jasmine.createSpyObj('$rootScope', ['$on']);
|
() => {
|
||||||
|
const $rootScope = jasmine.createSpyObj('$rootScope', ['$on']);
|
||||||
|
|
||||||
upgradeModule.$injector.get.and.callFake(
|
upgradeModule.$injector.get.and.callFake(
|
||||||
(name: string) => (name === '$rootScope') && $rootScope);
|
(name: string) => (name === '$rootScope') && $rootScope);
|
||||||
|
|
||||||
setUpLocationSync(upgradeModule);
|
setUpLocationSync(upgradeModule);
|
||||||
|
|
||||||
expect($rootScope.$on).toHaveBeenCalledTimes(1);
|
expect($rootScope.$on).toHaveBeenCalledTimes(1);
|
||||||
expect($rootScope.$on).toHaveBeenCalledWith('$locationChangeStart', jasmine.any(Function));
|
expect($rootScope.$on)
|
||||||
});
|
.toHaveBeenCalledWith('$locationChangeStart', jasmine.any(Function));
|
||||||
|
});
|
||||||
|
|
||||||
it('should navigate by url every time $locationChangeStart is broadcasted', () => {
|
fixmeIvy('FW-777: R3Injector doesn\'t support injectors as a provider') &&
|
||||||
const url = 'https://google.com';
|
it('should navigate by url every time $locationChangeStart is broadcasted', () => {
|
||||||
const pathname = '/custom/route';
|
const url = 'https://google.com';
|
||||||
const normalizedPathname = 'foo';
|
const pathname = '/custom/route';
|
||||||
const query = '?query=1&query2=3';
|
const normalizedPathname = 'foo';
|
||||||
const hash = '#new/hash';
|
const query = '?query=1&query2=3';
|
||||||
const $rootScope = jasmine.createSpyObj('$rootScope', ['$on']);
|
const hash = '#new/hash';
|
||||||
|
const $rootScope = jasmine.createSpyObj('$rootScope', ['$on']);
|
||||||
|
|
||||||
upgradeModule.$injector.get.and.returnValue($rootScope);
|
upgradeModule.$injector.get.and.returnValue($rootScope);
|
||||||
LocationMock.normalize.and.returnValue(normalizedPathname);
|
LocationMock.normalize.and.returnValue(normalizedPathname);
|
||||||
|
|
||||||
setUpLocationSync(upgradeModule);
|
setUpLocationSync(upgradeModule);
|
||||||
|
|
||||||
const callback = $rootScope.$on.calls.argsFor(0)[1];
|
const callback = $rootScope.$on.calls.argsFor(0)[1];
|
||||||
callback({}, url + pathname + query + hash, '');
|
callback({}, url + pathname + query + hash, '');
|
||||||
|
|
||||||
expect(LocationMock.normalize).toHaveBeenCalledTimes(1);
|
expect(LocationMock.normalize).toHaveBeenCalledTimes(1);
|
||||||
expect(LocationMock.normalize).toHaveBeenCalledWith(pathname);
|
expect(LocationMock.normalize).toHaveBeenCalledWith(pathname);
|
||||||
|
|
||||||
expect(RouterMock.navigateByUrl).toHaveBeenCalledTimes(1);
|
expect(RouterMock.navigateByUrl).toHaveBeenCalledTimes(1);
|
||||||
expect(RouterMock.navigateByUrl).toHaveBeenCalledWith(normalizedPathname + query + hash);
|
expect(RouterMock.navigateByUrl).toHaveBeenCalledWith(normalizedPathname + query + hash);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should work correctly on browsers that do not start pathname with `/`', () => {
|
fixmeIvy('FW-777: R3Injector doesn\'t support injectors as a provider') &&
|
||||||
const anchorProto = HTMLAnchorElement.prototype;
|
it('should work correctly on browsers that do not start pathname with `/`', () => {
|
||||||
const originalDescriptor = Object.getOwnPropertyDescriptor(anchorProto, 'pathname');
|
const anchorProto = HTMLAnchorElement.prototype;
|
||||||
Object.defineProperty(anchorProto, 'pathname', {get: () => 'foo/bar'});
|
const originalDescriptor = Object.getOwnPropertyDescriptor(anchorProto, 'pathname');
|
||||||
|
Object.defineProperty(anchorProto, 'pathname', {get: () => 'foo/bar'});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const $rootScope = jasmine.createSpyObj('$rootScope', ['$on']);
|
const $rootScope = jasmine.createSpyObj('$rootScope', ['$on']);
|
||||||
upgradeModule.$injector.get.and.returnValue($rootScope);
|
upgradeModule.$injector.get.and.returnValue($rootScope);
|
||||||
|
|
||||||
setUpLocationSync(upgradeModule);
|
setUpLocationSync(upgradeModule);
|
||||||
|
|
||||||
const callback = $rootScope.$on.calls.argsFor(0)[1];
|
const callback = $rootScope.$on.calls.argsFor(0)[1];
|
||||||
callback({}, '', '');
|
callback({}, '', '');
|
||||||
|
|
||||||
expect(LocationMock.normalize).toHaveBeenCalledWith('/foo/bar');
|
expect(LocationMock.normalize).toHaveBeenCalledWith('/foo/bar');
|
||||||
} finally {
|
} finally {
|
||||||
Object.defineProperty(anchorProto, 'pathname', originalDescriptor !);
|
Object.defineProperty(anchorProto, 'pathname', originalDescriptor !);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user