passed along to TestBed.configureTestingModule(). Automatically includes provideHttpClientTesting, MockErrorHandler, and MATERIAL_ANIMATIONS with animationsDisabled: true.
Set this before calling run() to mock the time at which the test starts.
ProtectedcleanThis is a hook for subclasses to override. It is called as the last step during run(), even if a previous step errored. This implementation does nothing, but if you override this it is still recommended to call super.cleanUp() in case this implementation does something in the future.
Returns whether any components match the given query.
ProtectedinitThis is a hook for subclasses to override. It is called during run(), before the test() callback. This implementation does nothing, but if you override this it is still recommended to call super.init() in case this implementation does something in the future.
Gets a service or other injectable from the root injector.
This implementation is a simple pass-through to TestBed.inject(), but subclasses may provide their own implementation. It is recommended to use this in your tests instead of using TestBed directly.
Returns whether this context is currently executing the AngularContext#run callback.
Runs test with fake timers enabled. It can use async/await, but be sure anything you await is already due to execute (e.g. if a timeout is due in 3 seconds, call .tick(3000) before awaiting its result).
Also runs the following in this order:
this.init()test()this.verifyPostTestConditions()this.cleanUp()ProtectedrunAdvance time and trigger change detection. It is common to call this with no arguments to trigger change detection without advancing time.
The unit of time amount represents. Accepts anything described in @s-libs/s-core's [TimeUnit]https://simontonsoftware.github.io/s-js-utils/typedoc/enums/timeunit.html enum.
ProtectedverifyRuns post-test verifications. This base implementation runs HttpTestingController.verify and MockErrorHandler.verify. It is OK for this method to throw an error to indicate a violation.
StaticgetReturns the current AngularContext that is in use, or undefined if there is not one. A context is defined to be "in use" from the time it is constructed until after its run() method completes.
Provides the foundation for an opinionated testing pattern.
vi.useFakeTimers. This gives you full control over the timing of everything by default.provideHttpClientTesting()to stub network requests without additional setup.This example tests a simple service that uses
HttpClientand is tested by usingAngularContextdirectly. More often,AngularContextwill be used as a super class. SeeComponentContextfor more common use cases.