我正在为Angular 7应用程序设置UT(使用茉莉花),以测试基于当前路线动画属性使用角度动画效果的方法。
我什至没有为茉莉花定义
//#region ANGULAR 7 SOURCE CODE
getAnimationEffect(outlet: RouterOutlet): string {
let currentAnimationEffect = '';
if (outlet && outlet.activatedRouteData) {
if (outlet.activatedRouteData['moduleIndex'] &&
outlet.activatedRouteData['moduleIndex'] > 0 &&
outlet.activatedRouteData['moduleIndex'] !== this.currentModuleIndex) {
this.currentModuleIndex = _.cloneDeep(outlet.activatedRouteData['moduleIndex']);
currentAnimationEffect = 'isModuleLanding';
} else {
currentAnimationEffect = outlet.activatedRouteData['animation'];
}
} else {
currentAnimationEffect = 'isModuleLanding';
}
return currentAnimationEffect;
}
//#endregion
//#region ANGULAR 7 UT
describe('testing routing stuff', () => {
const testRoutes: Routes = [
{
path: 'module',
data: { title: 'Module', moduleIndex: 1 }
},
{
path: 'tab',
data: { title: 'Module -> Tab', animation: 'tabLanding', moduleIndex: 1 }
},
{
path: 'detail',
data: { title: 'Module -> Tab -> Detail', animation: 'detailLanding', moduleIndex: 1 }
}
];
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [ RouterTestingModule.withRoutes(testRoutes) ],
...
})
.compileComponents();
}));
});
it('should get the animation effect that correspond to the current active route',
async(() => {
// Provoke navigation end to route 'module/tab/detail'
const event = new NavigationEnd(666, '/module/tab', '/module/tab/detail');
TestBed.get(Router).events.next(event);
// Get response to current active route animation effect that correspond to this route
const testAnimationEffect = componentBaseView.getAnimationEffect(<IDontKnowHowToDefineAParamHere>)
// Assert
expect(testAnimationEffect).toEqual('detailLadning');
})
);
});
//#endregion
我希望能够在当前激活的路由器的tab / x / details返回“ detailLanding”时测试该动画效果。
我不知道该如何设置,也无法找到任何方法可以在其中接收路由器出口的测试。
这里有什么想法吗?