运行单元测试时,此错误出现在TFS构建输出中
我只需在test.ts中添加一个导入就解决了这个问题
import { getTestBed } from '@angular/core/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';
import 'zone.js/dist/zone-testing';
**import 'hammerjs';**
declare const require: any;
// 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 );
添加以下提供程序为我修复了问题:
...
import { HAMMER_LOADER } from '@angular/platform-browser';
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ... ],
imports: [ ... ],
providers: [
...,
{ provide: HAMMER_LOADER, useValue: () => new Promise(() => {}) } ]
})
.compileComponents();
}));