本文整理汇总了TypeScript中@angular/router/upgrade.setUpLocationSync函数的典型用法代码示例。如果您正苦于以下问题:TypeScript setUpLocationSync函数的具体用法?TypeScript setUpLocationSync怎么用?TypeScript setUpLocationSync使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setUpLocationSync函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: setUpLocationSync
() => {
const $rootScope = jasmine.createSpyObj('$rootScope', ['$on']);
upgradeModule.$injector.get.and.callFake(
(name: string) => (name === '$rootScope') && $rootScope);
setUpLocationSync(upgradeModule);
expect($rootScope.$on).toHaveBeenCalledTimes(1);
expect($rootScope.$on).toHaveBeenCalledWith('$locationChangeStart', jasmine.any(Function));
});
示例2: it
it('should work correctly on browsers that do not start pathname with `/`', () => {
const anchorProto = HTMLAnchorElement.prototype;
const originalDescriptor = Object.getOwnPropertyDescriptor(anchorProto, 'pathname');
Object.defineProperty(anchorProto, 'pathname', {get: () => 'foo/bar'});
try {
const $rootScope = jasmine.createSpyObj('$rootScope', ['$on']);
upgradeModule.$injector.get.and.returnValue($rootScope);
setUpLocationSync(upgradeModule);
const callback = $rootScope.$on.calls.argsFor(0)[1];
callback({}, '', '');
expect(LocationMock.normalize).toHaveBeenCalledWith('/foo/bar');
} finally {
Object.defineProperty(anchorProto, 'pathname', originalDescriptor !);
}
});
示例3: it
it('should allow configuration to work with hash-based routing', () => {
const url = 'https://google.com';
const pathname = '/custom/route';
const normalizedPathname = 'foo';
const query = '?query=1&query2=3';
const hash = '#new/hash';
const combinedUrl = url + '#' + pathname + query + hash;
const $rootScope = jasmine.createSpyObj('$rootScope', ['$on']);
upgradeModule.$injector.get.and.returnValue($rootScope);
LocationMock.normalize.and.returnValue(normalizedPathname);
setUpLocationSync(upgradeModule, 'hash');
const callback = $rootScope.$on.calls.argsFor(0)[1];
callback({}, combinedUrl, '');
expect(LocationMock.normalize).toHaveBeenCalledTimes(1);
expect(LocationMock.normalize).toHaveBeenCalledWith(pathname);
expect(RouterMock.navigateByUrl).toHaveBeenCalledTimes(1);
expect(RouterMock.navigateByUrl).toHaveBeenCalledWith(normalizedPathname + query + hash);
});
示例4: expect
expect(() => setUpLocationSync(upgradeModule)).toThrowError(`