Your code should never borrow symbols from the outer scope of the module. This includes obvious browser APIs like window, console, document, but also imported functions and static class functions (including the new operator).
All such symbols must be provided to the class via dependency injection. Following are a couple of examples to illustrate this principle.
// foo.service.ts
@Injectable()
exportclassFooService{
publiconSomething(){
history.back();// No: Don't use a global API like that.
}
}
Instead, inject the symbol. For instance, you could just inject the Window object in here.
Another example is class constructors. Class constructors are static methods and cannot easilly be mocked with ng-vacuum (and in general too). Unless the class you are constructing is a simple data object like Point(x,y), Rect(x,y,w,h) or similar, you will want to uncouple the code using this class with a factory service.
Abstract away CSS selectors in a page object. This makes tests more readable but also makes it easier to update the test suite after the component template was changed.