angular_test 2.0.0

  • Readme
  • Changelog
  • Installing
  • 49

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() {

  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) => = '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:

  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:

2.0.0 #

New Features #

  • Supported FutureOr<void> for beforeChangeDetection.

  • NgZoneStabilizer waits for the longest pending timer during update().

  • Added isStable API to NgTestStabilizer.

  • Made NgTestStabilizerFactory public.

Breaking Changes #

  • Removed throwsInAngular. Use throwsA.

  • Removed NgTestFixture#query/queryAll, as debug-mode is being turned down.

  • Run DelegatingNgTestStabilizer stabilizers one by one instead of run all at once. update() for each stabilizers will be run at least once. After that, it will only be run if the current stabilizer is not stable.

  • pub run angular_test was entirely removed. Similar functionality is supported out of the box by build_runner:

$ pub run build_runner test
  • 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 version of pageloader in development that uses code generation. We'll consider re-adding support once available or through another package (i.e. angular_pageloader or similar).

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

Bug Fixes #

  • Deleted an unnecessary hostElement.append(componentRef.location).

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

  • Fixed a bug where _createDynamic does not preserve rootInjector.

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

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>*/(
expect(await pageObject.button.visibleText, 'Click count: 0');
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:

  angular_test: ^2.0.0

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';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Nov 7, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21


Detected platforms:

Low code quality prevents platform classification.

Health issues and suggestions

Fix lib/src/bootstrap.dart. (-86.85 points)

Analysis of lib/src/bootstrap.dart failed with 7 errors, 3 hints, including:

line 13 col 8: Target of URI doesn't exist: 'package:angular/src/core/render/api.dart'.

line 14 col 8: Target of URI doesn't exist: 'package:angular/src/platform/dom/shared_styles_host.dart'.

line 101 col 3: Undefined name 'sharedStylesHost'.

line 101 col 24: The function 'DomSharedStylesHost' isn't defined.

line 103 col 44: The name 'ViewRefImpl' isn't a type, so it can't be used in an 'as' expression.

Fix lib/compatibility.dart. (-0.50 points)

Analysis of lib/compatibility.dart reported 1 hint:

line 26 col 7: 'SlowComponentLoader' is deprecated and shouldn't be used.

Fix lib/src/frontend/bed.dart. (-0.50 points)

Analysis of lib/src/frontend/bed.dart reported 1 hint:

line 198 col 25: 'SlowComponentLoader' is deprecated and shouldn't be used.

Maintenance issues and suggestions

Fix platform conflicts. (-20 points)

Low code quality prevents platform classification.

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

exitCode: 255 stdout: parsing /tmp/pub-dartlang-dartdocJXFEUD/pkg/lib/angular_test.dart... parsing /tmp/pub-dartlang-dartdocJXFEUD/pkg/lib/compatibility.dart... stderr: Documenting angular_test... Unhandled exception: fatal error: unable to locate the input directory at /tmp/pub-cache-dirQTIYJE/hosted/ #0 new PackageMeta.fromDir (package:dartdoc/src/package_meta.dart:120:7) #1 new PackageMeta.fromFilename (package:dartdoc/src/package_meta.dart:109:24) #2 PackageBuilder._packageMetasForFiles (package:dartdoc/src/model.dart:6811:29) #3 PackageBuilder._parseLibraries (package:dartdoc/src/model.dart:6850:17)

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (angular).

Package is getting outdated. (-25.21 points)

The package was last published 65 weeks ago.

The package description is too short. (-18 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and angular_test.dart. Packages with multiple examples should provide example/

For more information see the pub package layout conventions.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.69.5 <3.0.0
angular ^5.0.0 5.3.1 6.0.0-alpha+1
meta ^1.1.4 1.1.8
Transitive dependencies
analyzer 0.35.4 0.39.1
analyzer_plugin 0.2.1
angular_ast 0.5.9 0.5.11
angular_compiler 0.4.3 0.4.5
args 1.5.2
async 2.4.0
build 1.2.1
build_config 0.4.1+1
built_collection 4.2.2
built_value 6.8.2 7.0.0
built_value_generator 6.8.2 7.0.0
charcode 1.1.2
checked_yaml 1.0.2
code_builder 3.2.0
collection 1.14.12
convert 2.1.1
crypto 2.1.3
csslib 0.14.6+1 0.16.1
dart_style 1.2.4 1.3.3
fixnum 0.10.11
front_end 0.1.14 0.1.29
glob 1.2.0
html 0.14.0+3
intl 0.15.8 0.16.0
js 0.6.1+1
json_annotation 3.0.0
kernel 0.3.14 0.3.29
logging 0.11.3+2
matcher 0.12.6
node_interop 1.0.3
node_io 1.0.1+2
package_config 1.1.0
path 1.6.4
pedantic 1.8.0+1
pub_semver 1.4.2
pubspec_parse 0.1.5
quiver 2.1.2+1
source_gen 0.9.4+4 0.9.4+6
source_span 1.5.5
stack_trace 1.9.3
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
watcher 0.9.7+12
yaml 2.2.0
Dev dependencies
build_runner ^0.10.0
build_test ^0.10.2+5
build_web_compilers ^0.4.0+4
test ^1.3.0