0

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

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Do you mean passing function that takes no arguments and returns nothing will trigger the clicks ?
No, passing a function is just like passing any other value. But line 120 calls the function passed as an argument. I've edited the answer to clarify that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.