NgTestBed<T extends Object> constructor
NgTestBed<T extends Object> (})
Create a new NgTestBed that uses the provided component
factory.
Some APIs are not supported outside of NgTestBed.useInitReflector
:
addProviders
will throw UnsupportedError; instead, the addInjector API allows you to wrap the previousInjector
, if any, to provide additional services. In most cases justrootInjector
is enough, and you could re-use providers viaGenerateInjector
.
void main() {
final ngTestBed = NgTestBed(
SomeComponentNgFactory,
rootInjector: ([parent]) => new Injector.map({
Service: new Service(),
}, parent),
);
}
Implementation
factory NgTestBed(
ComponentFactory<T> component, {
Element? host,
InjectorFactory rootInjector = _defaultRootInjector,
bool watchAngularLifecycle = true,
}) {
if (T == dynamic) {
throw GenericTypeMissingError();
}
return NgTestBed<T>._useComponentFactory(
component: component,
rootInjector: rootInjector,
host: host,
watchAngularLifecycle: watchAngularLifecycle,
);
}