angular_test 1.0.0-beta+4 copy "angular_test: ^1.0.0-beta+4" to clipboard
angular_test: ^1.0.0-beta+4 copied to clipboard

discontinuedreplaced by: ngtest
outdatedDart 1 only

Testing runner and library for AngularDart

angular_test #

Pub Package

Testing infrastructure and runner for AngularDart.

It's strongly recommended to view the test/ folder for examples and recommended patterns.

Usage #

angular_test is both a framework for writing tests for AngularDart components and a test runner that delegates to both pub serve and pub run test to run component tests using the AOT-compiler - angular_test does not function in reflective mode.

Example use:

@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';
}

You will need to also configure in pubspec.yaml to run code generation:

transformers:
  # Run the code generator on the entire package.
  - angular/transform/codegen

  # Run the reflection remover on tests that have AoT enabled.
  - angular/transform/reflection_remover:
      $include:
          - test/test_using_angular_test.dart

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

Running #

Use pub run angular_test - it will automatically run pub serve to run code generation (transformers) and pub run test to run browser tests on anything tagged with 'aot'. You'll also need to declare a specific browser test platform: dartium or content-shell are the most common choices. For example:

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

Use one or more

  • --test-arg to pass arguments to pub run test
  • --serve-arg to pass arguments to pub serve

Usage #

--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