angular_test 2.0.0-alpha copy "angular_test: ^2.0.0-alpha" to clipboard
angular_test: ^2.0.0-alpha copied to clipboard

discontinuedreplaced by: ngtest
outdatedDart 1 only

Testing runner and library for AngularDart

Pub package

Testing infrastructure and runner for AngularDart, used with the test package.

Documentation and examples:

Additional resources:

Overview #

angular_test is both a framework for writing tests for AngularDart components and a test runner that delegates to pub serve and pub run test to run component tests using the AOT compiler.

Note: angular_test does not function in reflective mode.

Here's an example of an AngularDart test:

@Tags(const ['aot'])
@TestOn('browser')
import 'dart:html';

import 'package:angular/angular.dart';
import 'package:angular_test/angular_test.dart';
import 'package:test/test.dart';

@AngularEntrypoint()
void main() {
  tearDown(disposeAnyRunningTest);

  test('should render "Hello World"', () async {
    final testBed = new NgTestBed<HelloWorldComponent>();
    final testFixture = await testBed.create();
    expect(testFixture.text, 'Hello World');
    await testFixture.update((c) => c.name = 'Universe');
    expect(testFixture.text, 'Hello Universe');
  });
}

@Component(selector: 'test', template: 'Hello {{name}}')
class HelloWorldComponent {
  String name = 'World';
}

To use angular_test, configure your package's pubspec.yaml as follows:

transformers:
  - angular:
      entry_points:
        - web/main.dart
        - test/**_test.dart

  # Allow test to proxy-load files so we can run AOT tests with pub serve.
  - test/pub_serve:
      $include: test/**_test.dart

  - dart_to_js_script_rewriter

To run tests, use pub run angular_test. It automatically runs pub serve to run code generation (transformers) and pub run test to run browser tests on anything tagged with 'aot'. Also declare a specific browser test platform, as described in the test package description; dartium and content-shell are the most common choices. Here's an example of running tests using the content shell:

pub run angular_test --test-arg=--tags=aot --test-arg=--platform=content-shell

Options #

The angular_test script can accept the following options:

--package              What directory containing a pub package to run tests in
                       (defaults to CWD)

-v, --[no-]verbose     Whether to display output of "pub serve" while running tests
    --help             Show usage
    --port             What port to use for pub serve.

                       **DEPRECATED**: Use --serve-arg=--port=.... If this is
                       not specified, and --serve-arg=--port is not specified, then
                       defaults to a value of "0" (or random port).

-S, --serve-arg        Pass an additional argument=value to `pub serve`

                       Example use --serve-arg=--mode=release

-t, --run-test-flag    What flag(s) to include when running "pub run test".
                       In order to have a fast test cycle, we only want to run
                       tests that have Angular compilation required (all the ones
                       created using this package do).

                       **DEPRECATED**: Use --test-arg=--tags=... instead

-p, --platform         What platform(s) to pass to `pub run test`.

                       **DEPRECATED**: Use --test-arg=--platform=... instead

-n, --name             A substring of the name of the test to run.
                       Regular expression syntax is supported.
                       If passed multiple times, tests must match all substrings.

                       **DEPRECATED**: Use --test-arg=--name=... instead

-N, --plain-name       A plain-text substring of the name of the test to run.
                       If passed multiple times, tests must match all substrings.

                       **DEPRECATED**: Use --test-arg=--plain-name=... instead

-T, --test-arg         Pass an additional argument=value to `pub run test`

                       Example: --test-arg=--name=ngIf