NgTestBed<T extends Object> class

An immutable builder for creating a pre-configured AngularDart application.

The root component type T that is created is essentially the same as a root application component you would create normally with bootstrap.

For a simple test:

group('$HelloWorldComponent', () {
  tearDown(() => disposeAnyRunningTest());

  test('should render "Hello World"', () async {
    var bed = new NgTestBed<HelloWorldComponent>();
    var fixture = await bed.create();
    expect(fixture.text, contains('Hello World'));
  });
});

New behavior and features can be added in a hierarchy of tests:

group('My tests', () {
  NgTestBed<HelloWorldComponent> bed;
  NgTestFixture<HelloWorldComponent> fixture;

  setUp(() => bed = new NgTestBed<HelloWorldComponent>());
  tearDown(() => disposeAnyRunningTest());

  test('should render "Hello World", () async {
    fixture = await bed.create();
    expect(fixture.text, contains('Hello World'));
  });

  test('should render "Hello World" in all-caps', () async {
    bed = bed.addProviders(const [
      const Provider(TextFormatter, useClass: AllCapsTextFormatter),
    ]);
    fixture = await bed.create();
    expect(fixture.text, contains('HELLO WORLD'));
  });
});

Constructors

NgTestBed(ComponentFactory<T> component, {Element? host, InjectorFactory rootInjector = _defaultRootInjector, bool watchAngularLifecycle = true})
Create a new NgTestBed that uses the provided component factory.
factory
NgTestBed.useInitReflector({Element? host, InjectorFactory? rootInjector, bool watchAngularLifecycle = true})
Create a new empty NgTestBed that creates a component type T.
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

addInjector(InjectorFactory factory) NgTestBed<T>
Returns a new instance of NgTestBed with the root injector wrapped.
addProviders(Iterable<Object> providers) NgTestBed<T>
Returns a new instance of NgTestBed with providers added.
addStabilizers(Iterable<NgTestStabilizerFactory> stabilizers) NgTestBed<T>
Returns a new instance of NgTestBed with stabilizers added.
create({FutureOr<void> beforeComponentCreated(Injector)?, FutureOr<void> beforeChangeDetection(T instance)?}) Future<NgTestFixture<T>>
Creates a new test application with T as the root component.
fork<E extends T>({Element? host, ComponentFactory<E>? component, Iterable<Object>? providers, InjectorFactory? rootInjector, NgTestStabilizerFactory? stabilizer}) NgTestBed<E>
Creates a new instance of NgTestBed.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
setComponent<E extends T>(ComponentFactory<E> component) NgTestBed<E>
Returns a new instance of NgTestBed with component overrode.
setHost(Element host) NgTestBed<T>
Returns a new instance of NgTestBed with host overrode.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited