Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

default route templateUrl causes unexpected GET error in all module unit test specs #2717

Closed
@jardilio

Description

@jardilio

I have an application that is broken down into several modules, each of which defines its own routes to handle and contains several controllers, services...all thru separate files which register themselves to the appropriate module(s).

When I create unit test specs for any particular service, I hit an issue where I get an 'expected GET' request as a result of a templateUrl linked to the default route in the module. I don't expect to have to write an expect in every spec for the route which is completely unrelated to the controller, service, directive...which I am unit testing.

I have created a plunk to test the situation here: http://plnkr.co/edit/jfetatSfBguwEGT59QJ4?p=preview

The actual combination of items that cause such a situation are as follows:

  1. Create a default route for path '/' AND give it a templateUrl value (using template is not an issue)
  2. Somewhere in your module chain for which you are unit testing, contain a reference to the $route service

When the above criteria are met, there isn't a good way to separate the unit tests since the module configuration defines route mapping and modules reference to $route initialize code behind the scenes to begin loading the default routes templateUrl thus creating an unexpected GET request for the templateUrl.

The only workaround I have is to explicitly place an $httpBackend.expectGET('path/to/default/template.html') in every test that uses this module reference, but this is not expected and completely unrelated to the test itself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions