1
\$\begingroup\$

This is a piece of test code made for the Angular application.

The router object is a mock provided by the RouterTestingModule dependency. I wonder if such a test can be considered a unit test (because it actually tests only one element and the fact that it calls some method - without checking its result), or should it be called an integration test (due to the fact that it still call external dependence)?

it('should trigger the navigation to `/home`', async(() => {
  const link = fixture.debugElement.nativeElement.querySelector('.home-link');

  link.click();

  expect(router.navigateByUrl).toHaveBeenCalled();
}))

\$\endgroup\$
3
  • \$\begingroup\$ Welcome to Code Review! Did you create this code or do you maintain it? \$\endgroup\$ Commented Jul 2, 2019 at 22:55
  • \$\begingroup\$ Welcome to Code Review! The current question title, which states your concerns about the code, is too general to be useful here. Please edit to the site standard, which is for the title to simply state the task accomplished by the code. Please see How to get the best value out of Code Review: Asking Questions for guidance on writing good question titles. \$\endgroup\$ Commented Jul 3, 2019 at 7:10
  • 2
    \$\begingroup\$ I'm voting to close this question as off-topic because it isn't asking for code review \$\endgroup\$ Commented Jul 3, 2019 at 7:53

1 Answer 1

1
\$\begingroup\$

Since

  • router object is a mock, and
  • the fact that it calls some method - without checking its result

You have a unit test, more specifically a whitebox test, as opposed to a blackbox test that tests the output of some method.

For it to become an integration test, you would have use a router instead of a mock.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.