Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
与全球供应商进行Angular 2测试_Angular_Karma Runner_Angular Cli - Fatal编程技术网

与全球供应商进行Angular 2测试

与全球供应商进行Angular 2测试,angular,karma-runner,angular-cli,Angular,Karma Runner,Angular Cli,我正在angular cli项目中测试许多组件,并且在其中一些组件中使用RouterTestingModule来存根路由器。我只想将RouterTestingModule添加到所有测试中,这样就不必选择性地添加它 我将它添加到test.js中的测试设置中,如下所示,但它似乎没有包含在组件的测试模块中。这是包含“全球”提供商的正确方式吗 Promise.all([ System.import('@angular/core/testing'), System.import('@ang

我正在angular cli项目中测试许多组件,并且在其中一些组件中使用
RouterTestingModule
来存根路由器。我只想将
RouterTestingModule
添加到所有测试中,这样就不必选择性地添加它

我将它添加到
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

这只能调用一次,以便为 当前平台上的当前测试套件


虽然有点晚,但解决方案是将一个提供程序数组传递给platformBrowserDynamicTesting()函数

Promise.all([
系统导入(“@angular/core/testing”),
System.import(“@angular/platform browser dynamic/testing”),
System.import(“@angular/router/testing”),
])
//首先,初始化角度测试环境。
.然后(([测试,测试浏览器,测试路由器])=>{
testing.getTestBed().initTestEnvironment(
testingBrowser.Browser动态测试模块,
testingBrowser.PlatformBrowser动态测试([…])
);
})
//然后我们找到所有的测试。
.then(()=>require.context('./',true,/\.spec\.ts/))
//并加载模块。
.then(context=>context.keys().map(context))
//最后,启动Karma来运行测试。
.然后(uuuu业力开始,uuu业力错误)