angular-cn/modules_dart/angular2_testing
Julie Ralph b0cebdba6b feat(test): allow tests to specify the platform and application providers used
With providers split into bundles, the test injector is now able to
use providers for a given bundle. Suggested provider lists for tests are
available in `angular2/platform/testing/<platform>`.

Change the providers for a test suite using `setBaseTestProviders`. This
should be done once at the start of the test suite, before any test cases
run.

BREAKING CHANGE: Tests are now required to use `setBaseTestProviders`
to set up. Assuming your tests are run on a browser, setup would change
as follows.

Before:

```js
// Somewhere in test setup
import {BrowserDomAdapter} from 'angular2/src/platform/browser/browser_adapter';
BrowserDomAdapter.makeCurrent
```

After:

```js
// Somewhere in the test setup
import {setBaseTestProviders} from 'angular2/testing';
import {
  TEST_BROWSER_PLATFORM_PROVIDERS,
  TEST_BROWSER_APPLICATION_PROVIDERS
} from 'angular2/platform/testing/browser';

setBaseTestProviders(TEST_BROWSER_PLATFORM_PROVIDERS,
                     TEST_BROWSER_APPLICATION_PROVIDERS);
```

Closes #5351, Closes #5585

Closes #5975
2016-01-13 02:11:06 +00:00
..
lib feat(test): allow tests to specify the platform and application providers used 2016-01-13 02:11:06 +00:00
test feat: camelCase Angular (kebab-case removal) 2015-12-09 19:59:40 -08:00
README.md feat(test): add angular2_testing dart library 2015-12-03 11:33:46 -08:00
pubspec.yaml feat(testing): package angular2_testing to prepare it for publishing 2015-12-09 03:01:21 +00: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.