【问题标题】:WARN: 'The "slidestart" event cannot be bound because Hammer.JS is not loaded and no custom loader has been specified.'警告:“无法绑定“slidestart”事件,因为 Hammer.JS 未加载且未指定自定义加载器。
【发布时间】:2020-07-15 12:46:12
【问题描述】:

运行单元测试时,此错误出现在 TFS 构建输出中

【问题讨论】:

    标签: angular unit-testing tfs tfsbuild


    【解决方案1】:

    我通过简单地将导入添加到 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 );
    
    

    【讨论】:

      【解决方案2】:

      添加以下提供商为我解决了这个问题:

      ...
      import { HAMMER_LOADER } from '@angular/platform-browser';
      
      beforeEach(async(() => {
          TestBed.configureTestingModule({
            declarations: [ ... ],
            imports: [ ... ],
            providers: [
              ...,
              { provide: HAMMER_LOADER, useValue: () => new Promise(() => {}) } ]
          })
          .compileComponents();
        }));
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-11-13
        • 1970-01-01
        • 2012-10-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-01-19
        相关资源
        最近更新 更多