mercredi 26 juin 2019

What's the difference between TestBed.get and new Service(...dependencies)

The angular guide demonstrates two different ways of testing, one by calling new Service() and providing the dependencies to the constructor directly, and the second using dependency injection by calling TestBed.get(Service).

Both of these seem functionally identical to me, except when I call TestBed.get() consecutively it does not call the constructor after the first call.

The angular documentation also mentions that TestBed.get() is deprecated (even though the guide still references it!) and that I should use Type or InjectionToken instead, but I do not see how either of these classes could replace TestBed.get().

Aucun commentaire:

Enregistrer un commentaire