I'm writing some unit tests to test an Angular Router. In the test, I have code like this:
1expect(location.path()).toBe('/something');
IntelliJ is giving me errors, saying it can't find the path value:
Clearly the path() method exists on the Angular Location object, so what was the cause of the error?
Apparently there is a JavaScript Location object.
The browser Location object does not contain a path() function even though the Angular one does.
Since Location exists natively, IntelliJ did not import the Angular library, and I didn't notice until I tried to run the code.
The fix is pretty simple. Just import the Angular Location library manually:
1import {Location} from "@angular/common";
And you should be good to run your code and unit tests without any errors.