我目前有一個混合角應用程序(2.4.9和1.5.0)使用angular-cli。目前,運行我們的應用程序時,我們能夠正確地引導了1.5應用:角1.x/2混合,業力測試不引導ng1應用程序
// main.ts
import ...
platformBrowserDynamic().bootstrapModule(AppModule).then(platformRef => {
angular.element(document).ready(() => {
const upgrade = platformRef.injector.get(UpgradeModule) as UpgradeModule;
upgrade.bootstrap(document.body, ['myApp'], {strictDi: true});
});
});
然而,在我們test.ts
文件:
// test.ts
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
import ...;
declare var __karma__: any;
declare var require: any;
__karma__.loaded = function() {};
getTestBed().initTestEnvironment(
BrowserDynamicTestingModule,
// I'm assuming that I need to call 'boostrapModule()' somehow here...
platformBrowserDynamicTesting()
);
const context = require.context('./', true, /\.spec\.ts$/);
context.keys().map(context);
__karma__.start();
我不完全知道如何引導我們的1.5應用程序進入測試環境,我所得到的全部是Module 'myApp' is not available!
,我的Google技巧未能找到一個例子。
可能很好地移除'declare var __karma__:any;'並使用實際的'@ types/karma'包。這不會導致你的錯誤,但是你的代碼中的每一個'declare const lib:any;'都會丟掉通常很有用的工具。 –
我必須承認,當我讀到「Angular 1.x/2 Hybrid」時,我不相信這樣的事情甚至是可能的。 – wheeler