Angular 路由测试-Location.path()始终返回空&引用;
我跟在后面。这是我发现的唯一一个测试路由的现代示例。最后,我想使用模拟组件。可悲的是,它不起作用 路由器:应用程序导航到“”将您重定向到/主页 预期“”为“/home” 及 路由器:应用程序导航到“搜索”将带您进入/搜索 预期“”为“/search” 如果我更换,则会出现相同的问题:Angular 路由测试-Location.path()始终返回空&引用;,angular,angular-routing,angular2-testing,Angular,Angular Routing,Angular2 Testing,我跟在后面。这是我发现的唯一一个测试路由的现代示例。最后,我想使用模拟组件。可悲的是,它不起作用 路由器:应用程序导航到“”将您重定向到/主页 预期“”为“/home” 及 路由器:应用程序导航到“搜索”将带您进入/搜索 预期“”为“/search” 如果我更换,则会出现相同的问题: imports: [ RouterTestingModule.withRoutes(routes)] //by imports: [ RouterModule.forRoot(routes)] 你们有什么想法吗?
imports: [ RouterTestingModule.withRoutes(routes)] //by
imports: [ RouterModule.forRoot(routes)]
你们有什么想法吗?这不能解决问题。但是一种解决方法是使用E2E而不是单元测试
describe('navigation', () => {
it('root path should redirect to /app', () => {
browser.get('http://localhost:49152');
browser.getCurrentUrl().then((url) =>
expect(url).toBe('http://localhost:49152/app')
);
});
});
这并不能解决问题。但是一种解决方法是使用E2E而不是单元测试
describe('navigation', () => {
it('root path should redirect to /app', () => {
browser.get('http://localhost:49152');
browser.getCurrentUrl().then((url) =>
expect(url).toBe('http://localhost:49152/app')
);
});
});