使用 angular2的angular-cli时,运行 ng test报错

https://github.com/angular/an...
上的步骤安装好了angular-cli,执行ng server时正常运行,执行ng test时,报错了,test.ts文件里报错,说Cannot find name 'declare
下面是test.ts里的代码

import './polyfills.ts';

import 'zone.js/dist/long-stack-trace-zone';
import 'zone.js/dist/proxy.js';
import 'zone.js/dist/sync-test';
import 'zone.js/dist/jasmine-patch';
import 'zone.js/dist/async-test';
import 'zone.js/dist/fake-async-test';

// Unfortunately there's no typing for the `__karma__` variable. Just declare it as any.
declare
var __karma__: any;
declare
var require: any;

// Prevent Karma from running prematurely.
__karma__.loaded = function() {};


Promise.all([
        System.import('@angular/core/testing'),
        System.import('@angular/platform-browser-dynamic/testing')
    ])
    // First, initialize the Angular testing environment.
    .then(([testing, testingBrowser]) => {
        testing.getTestBed().initTestEnvironment(
            testingBrowser.BrowserDynamicTestingModule,
            testingBrowser.platformBrowserDynamicTesting()
        );
    })
    // 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);
    
    

clipboard.png

clipboard.png

不知道哪里的问题?

阅读 5.8k
1 个回答

我有点怀疑是不是因为你使用 declare 的时候换行了?

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题