0

Currently in routes unit test I'm testing if appropriate controller and template are called, like seen here. Also, in some routes I have resolved object. I can access them like:

expect($route.routes['/someroute'].resolve.name_of_field).not.toBe(null);

My question is: Should I check for resolved objects in routes unit test because they are part of routing config on one hand but on the other should I cover that by unit testing services that are used for resolving objects?

Community
  • 1
  • 1
NenadPavlov
  • 217
  • 1
  • 2
  • 10

2 Answers2

0

I think it is better to have separate unit test for resolving objects.

0

When unit testing related components, you should think of each of them as having a specific "job", and you want to test that it does that job, e.g. controller's job can be "receive data, pass them to the $scope/ViewModel", service's job "provide data", and the router's job "given an url, resolve data from the correct service and pass them to the correct controller".

So to answer your question: when testing routes that have resolves, you should mock the services that provide them, and verify that the correct controller gets called with the mocked resolve from the service.

pansay
  • 687
  • 8
  • 11