【发布时间】:2020-07-15 12:46:12
【问题描述】:
运行单元测试时,此错误出现在 TFS 构建输出中
【问题讨论】:
标签: angular unit-testing tfs tfsbuild
运行单元测试时,此错误出现在 TFS 构建输出中
【问题讨论】:
标签: angular unit-testing tfs tfsbuild
我通过简单地将导入添加到 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();
}));
【讨论】: