passed along to TestBed.configureTestingModule()
. Automatically includes HttpClientTestingModule for you.
Set this before calling run()
to mock the time at which the test starts.
Protected
cleanPerforms any cleanup needed at the end of each test. This base implementation calls discardPeriodicTasks
and flush
to avoid an error from the fakeAsync
zone.
Protected
initGets 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.
Runs test
in a fakeAsync
zone. 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 await
ing its result).
Also runs the following in this order, all within the same zone:
this.init()
test()
this.verifyPostTestConditions()
this.cleanUp()
Protected
runAdvance 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.
Protected
verifyRuns post-test verifications. This base implementation runs HttpTestingController.verify
and MockErrorHandler.verify. Unlike #cleanUp, it is OK for this method to throw an error to indicate a violation.
Static
getReturns 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.
fakeAsync
zone. This gives you full control over the timing of everything by default.This example tests a simple service that uses
HttpClient
, and is tested by usingAngularContext
directly. More oftenAngularContext
will be used as a super class. See ComponentContext for more common use cases.