angular_test 2.0.0-alpha+11

  • Readme
  • Changelog
  • Installing
  • 44

angular_test #

Pub package

Testing infrastructure AngularDart, used with the build_runner package.

Documentation and examples:

NOTE: Some of the guides above are out of date the for the latest angular_test versions.

Additional resources:

Overview #

angular_test is a library for writing tests for AngularDart components.

// Assume this is 'my_test.dart'.
import 'my_test.template.dart' as ng;

void main() {
  ng.initReflector();
  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:

dev_dependencies:
  build_runner: ^0.8.0
  build_test: ^0.10.0
  build_web_compilers: ^0.4.0

IMPORTANT: angular_test will not run without these dependencies set.

To run tests, use pub run build_runner test. It automatically compiles your templates and annotations with AngularDart, and then compiles all of the Dart code to JavaScript in order to run browser tests. Here's an example of using Chrome with Dartdevc:

pub run build_runner test -- -p chrome

For more information using pub run build_runner test, see the documentation: https://github.com/dart-lang/build/tree/master/build_runner#built-in-commands

2.0.0-alpha+11 #

  • Fixed a bug where a WillNeverStabilizeError was thrown whenever there was a non-zero length Timer being executed. This was due to a bug in how the NgStabilizer was executing - constantly calling the update function instead of calling it once and waiting for stabilization.

  • Fixed a bug where stabilizers are considered stable even when some of them are not.

2.0.0-alpha+10 #

  • Fixed a bug where _createDynamic does not preserve rootInjector.

2.0.0-alpha+9 #

  • pub run angular_test was entirely removed. This hasn't worked since 2.0.0-alpha+3, but instead threw an error message reminding users it was no longer supported.

2.0.0-alpha+8 #

  • The minimum SDK version is now sdk: ">=2.0.0-dev.46.0 <2.0.0".

  • DEPRECATED: throwsInAngular is now a no-op, and can be removed.

2.0.0-alpha+7 #

  • Maintenance release, supporting newer package versions.

2.0.0-alpha+6 #

  • Maintenance release, supporting newer package versions.

2.0.0-alpha+5 #

  • Maintenance release, supporting newer package versions.

2.0.0-alpha+4 #

  • Removed built-in support for package:pageloader. The current version of pageloader relies on dart:mirrors, which is being removed from the web compilers (dart2js, dartdevc). There is a new (internal-only, right now) version of pageloader in development that uses code generation, but it is not available externally yet. We'll consider re-adding support once available or through another package (i.e. angular_pageloader or similar).

  • Added NgTestBed.forComponent, which takes a ComponentFactory<T>, and optionally an InjectorFactory. This allows writing tests entirely free of any invocations of initReflector().

  • BREAKING CHANGE: Adding stabilizers to NgTestBed now takes a factory function of type NgTestStabilizer Function(Injector), which is aliased as NgTestStabilizerFactory. This allows using NgTestBed without any dynamic reflective factories (i.e. initReflector()) and doesn't have impact to most users.

2.0.0-alpha+3 #

  • Removed support for pub run angular_test. This is no longer strictly needed, as it was just a convenience for running both the build system and test runner. Similar functionality is supported out of the box by build_runner:
$ pub run build_runner test

2.0.0-alpha+2 #

Maintenance release, to support the latest package:angular alpha.

2.0.0-alpha+1 #

  • Added support for build.yaml.

2.0.0-alpha #

NOTE: This was previously 1.0.2-alpha+1, but since this has major breaking changes that make it incompatible with the 1.x.x releases in order to support angular 5.x.x, this will now be the 2.0.0 alpha release.

  • Add support for the use of an externally launched pub serve by using "none" as the value of --experimental-serve-script.

1.0.2-alpha+1 #

  • Use the new generic function syntax, stop using package:func.
  • Support breaking changes and deprecations in angular 5.0.0-alpha+1.

1.0.2-alpha #

  • Support breaking changes in angular 5.0.0-alpha

1.0.1 #

Cleanup #

  • Remove dependency on angular_router.

1.0.0 #

Breaking Changes & Deprecations

  • Throws in bootstrapping if the root component does not use default change detection. AngularDart does not support OnPush or other change detection strategies on the root component.

  • Pub serve now defaults to a random unused port (instead of 8080) and --port is deprecated. Going forward the supported way to supply this argument is via --serve-arg:

$ pub run angular_test --serve-arg=port=1234
  • Option --run-test-flag (-t) is now deprecated, and no longer has a default value of aot. Tags are still highly encouraged in order to have faster compilation times! Use --test-arg instead:
$ pub run angular_test --test-arg=--tags=aot
  • Option --platform (-p) is now Deprecated, and no longer has a default value of content-shell, which was not always installed on host machines. Instead use --test-arg:
$ pub run angular_test --test-arg=--platform=content-shell
  • Option --name (-n) and --simple-name (-N) are also deprecated. Use --test-arg=--name= and --test-arg=--simple-name= instead.

  • Changes to compatibility.dart might not be considered in future semver updates, and it highly suggested you don't use these APIs for any new code.

  • Change NgTestFixture.update to have a single optional parameter

Features #

  • Add assertOnlyInstance to fixture to remove some boilerplate around testing the state of a instance. Only use to test state, not to update it.

  • Added --serve-arg and --test-arg, which both support multiple arguments in order to have better long-term support for proxying to both pub serve and pub run test without frequent changes to this package. For example to use the [DartDevCompiler (dartdevc)]:

$ pub run angular_test --serve-arg=web-compiler=dartdevc
  • Add support for setting a custom PageLoader factory:
testBed = testBed.setPageLoader(
  (element) => new CustomPageLoader(...),
);
  • Add support for query and queryAll to NgTestFixture. This works similar to the update command, but is called back with either a single or multiple child component instances to interact with or run expectations against:
// Assert we have 3 instances of <child>.
await fixture.queryAll(
  (el) => el.componentInstance is ChildComponent,
  (children) {
    expect(children, hasLength(3));
  },
);
  • Add built-in support for package:pageloader:
final fixture = await new NgTestBed<TestComponent>().create();
final pageObject = await fixture.getPageObject/*<ClickCounterPO>*/(
  ClickCounterPO,
);
expect(await pageObject.button.visibleText, 'Click count: 0');
await pageObject.button.click();
expect(await pageObject.button.visibleText, 'Click count: 1');

Fixes #

  • Workaround for pub {serve|build} hanging on angular_test as a dependency.

  • Fixes a bug where the root was not removed from the DOM after disposed.

  • Added a missing dependency on package:func.

  • Properly fix support for windows by using pub.bat.

  • Replace all uses of generic comment with proper syntax.

  • Fixed a bug where activeTest was never set (and therefore disposed).

  • Fixed a bug where pub, not pub.bat, is run in windows.

  • Update pubspec.yaml so it properly lists AngularDart 3.0.0-alpha

  • Fix the executable so pub run angular_test can be used

  • Fix a serious generic type error when NgTestBed is forked

  • Fix a generic type error

  • Added compatibility.dart, a temporary API to some users migrate

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  angular_test: ^2.0.0-alpha+11

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:angular_test/angular_test.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
88
Health:
Code health derived from static analysis. [more]
--
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
--
Overall:
Weighted score of the above. [more]
44
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Analysis issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://dart.dev/dart-2#migration.

Maintenance issues and suggestions

Make sure dartdoc successfully runs on your package's source files. (-10 points)

Dependencies were not resolved.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.55.0 <2.0.0