angular-cn/modules_dart/angular2_testing
Vikram Subramanian 35cd0ded22 chore(testing): Refactor test methods to have a uniform interface.
Remove FunctionWithParamTokens.

All test wrappers async, fakeAsync and inject now return just a Function instead of FunctionWithParamTokens. This makes them directly consumable by the test framework. Also the test framework code does not have to handle a union of Function and FunctionWithParamTokens everywhere.

The Function returned by the above methods are considered asynchronous by the test framework if they return a Promise, synchronous otherwise.

Closes #8257
2016-04-28 01:16:25 +00:00
..
lib chore(testing): Refactor test methods to have a uniform interface. 2016-04-28 01:16:25 +00:00
test feat(core): separate refs from vars. 2016-04-28 01:13:40 +00:00
README.md feat(test): add angular2_testing dart library 2015-12-03 11:33:46 -08:00
pubspec.yaml refactor(view_compiler): codegen DI and Queries 2016-04-13 14:43:48 -07:00

README.md

Contains helpers to run unit tests for angular2 components and injectables, backed by the package:test library.

Usage

Update the dev dependencies in your pubspec.yaml to include the angular testing and test packages:

dev_dependencies:
  test: '^0.12.6'
  angular2_testing: any
  

Then in your test files, use angular2_testing helpers in place of setUp and test:

import 'package:test/test.dart';
import 'package:angular2_testing/angular2_testing.dart';

void main() {
  // This must be called at the beginning of your tests.
  initAngularTests();

  // Initialize the injection tokens you will use in your tests.
  setUpProviders(() => [provide(MyToken, useValue: 'my string'), TestService]);

  // You can then get tokens from the injector via ngSetUp and ngTest.
  ngSetUp((TestService testService) {
    testService.initialize();
  });

  ngTest('can grab injected values', (@Inject(MyToken) token, TestService testService) {
    expect(token, equals('my string'));
    expect(testService.status, equals('ready'));
  });
}

Examples

A sample test is available in test/angular2_testing_test.dart.