Reputation: 1011
I am reading the official examples of angular routing testing from here . I didn't understand how heroClick()
does trigger click.
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');
});
Here is a link to the stackblitz example
Upvotes: 0
Views: 49
Reputation: 1012
heroClick
is a parameter passed to the tests()
function in line 84. It's a function that takes no arguments and returns nothing. On line 120, heroClick()
calls whatever was passed to tests()
.
On lines 27 and 48 tests()
is called, passing different functions clickForShallow
and clickForDeep
, defined just below their usages. Those function simulate the clicks by interacting with the elements in the component.
Upvotes: 1