3
角度のあるcliプロジェクトで多くのコンポーネントをテストしており、そのうちのいくつかでRouterTestingModule
を使用してルータをスタブしています。すべてのテストにRouterTestingModule
を追加して、選択的に追加する必要はありません。グローバルプロバイダによる角度2のテスト
私はそれを以下のようにtest.js
のテスト設定に追加しましたが、コンポーネントのテストモジュールには含まれていないようです。これは "グローバル"プロバイダを含める正しい方法ですか?
Promise.all([
System.import('@angular/core/testing'),
System.import('@angular/platform-browser-dynamic/testing'),
System.import('@angular/router/testing'),
])
// First, initialize the Angular testing environment.
.then(([testing, testingBrowser, testingRouter]) => {
testing.getTestBed().initTestEnvironment(
testingBrowser.BrowserDynamicTestingModule,
testingBrowser.platformBrowserDynamicTesting(),
testingRouter.RouterTestingModule,
);
})
// Then we find all the tests.
.then(() => require.context('./', true, /\.spec\.ts/))
// And load the modules.
.then(context => context.keys().map(context))
// Finally, start Karma to run the tests.
.then(__karma__.start, __karma__.error);
ドキュメントを約initTestEnvironment
これを言う:
これは、現在のプラットフォーム上 現在のテストスイートのための共通のプロバイダを設定するには、一度呼び出すことができます。