Jasmine 角布线元件测试
我正在阅读的角度路由测试的官方例子。我不明白Jasmine 角布线元件测试,jasmine,angular-test,Jasmine,Angular Test,我正在阅读的角度路由测试的官方例子。我不明白heroClick()如何触发单击 it('should tell ROUTER to navigate when hero clicked', () => { heroClick(); <------- how does this work !? // trigger click on first inner <div class="hero"> // args passed to router
heroClick()
如何触发单击
it('should tell ROUTER to navigate when hero clicked', () => {
heroClick(); <------- how does this work !? // trigger click on first inner <div class="hero">
// args passed to router.navigateByUrl() spy
const spy = router.navigateByUrl as jasmine.Spy;
const navArgs = spy.calls.first().args[0];
// expecting to navigate to id of the component's first hero
const id = comp.heroes[0].id;
expect(navArgs).toBe('/heroes/' + id, 'should nav to HeroDetail for first hero');
});
it('当英雄点击时应该告诉路由器导航',()=>{
heroClick();heroClick
是传递给第84行中的tests()
函数的参数。它是一个不带参数且不返回任何内容的函数。在第120行,heroClick()
调用传递给tests()
的任何内容
在第27行和第48行<代码>测试()调用
,传递不同的函数clickForShallow
和clickForDeep
,这些函数定义在其用法下面。这些函数通过与组件中的元素交互来模拟单击。您的意思是传递不带参数且不返回任何内容的函数将触发单击吗?不,传递函数就像传递任何其他值一样。但是第120行调用作为参数传递的函数。我编辑了答案以澄清这一点。