run() will create a component of this type before running the rest of your test.
passed along to TestBed.configureTestingModule(). Automatically includes everything provided by AngularContext.
The ComponentFixture for a synthetic wrapper around your component. Available within the callback to run().
Set this before calling run() to mock the time at which the test starts.
Assign inputs to your component. Can be called before run() to set the initial inputs, or within run() to update them and trigger all the appropriate change detection and lifecycle hooks.
Assign CSS styles to the div wrapping your component. Can be called before or during run(). Accepts an object with the same structure as the ngStyle directive.
ctx.assignWrapperStyles({
width: '400px',
height: '600px',
margin: '20px auto',
border: '1px solid',
});
ProtectedcleanPerforms any cleanup needed at the end of each test. This implementation destroys fixture and calls the super implementation.
Use within run() to get your instantiated component.
Returns whether any components match the given query.
ProtectedinitConstructs and initializes your component. Called during run() before it executes the rest of your test.
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 pattern for component tests.
AngularContextrun().TestBed.createComponent()directly.APP_INITIALIZERs to complete before instantiating the component. A caveat, they must not include asetTimeoutdelay, or the test will hang.A very simple example:
A full example, with routing and a component harness. This is the full code for a tiny Angular app: