我将 angular 4 更新为 angular 5 并在运行测试时出错:
错误是:
t.ts(20,11): error TS2339: Property 'loaded' does not exist on type '{}'.src/test.ts(28,25): error TS2339: Property 'context' does not exist on type '{}'.
src/test.ts(32,11): error TS2339: Property 'start' does not exist on type '{}'.
我可以看到 test.js 有打字稿编译错误。我的打字稿版本是 2.4.2
这是 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';
import { getTestBed } from '@angular/core/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';
// Unfortunately there's no typing for the `__karma__` variable. Just declare it as any.
declare var __karma__: {};
declare var require: {};
// Prevent Karma from running prematurely.
__karma__.loaded = function () {};
// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(
BrowserDynamicTestingModule,
platformBrowserDynamicTesting()
);
// Then we find all the tests.
const context = require.context('./', true, /\.spec\.ts/);
// And load the modules.
context.keys().map(context);
// Finally, start Karma to run the tests.
__karma__.start();
升级后是否需要修改 test.ts 文件?如果是什么?