简体   繁体   English

如何在每次执行文本时取消显示“ WARN:'找不到HammerJS。”?

[英]How can I suppress “WARN: 'Could not find HammerJS.” on each text execution?

When executing tests, each test logs the following: 执行测试时,每个测试记录以下内容:

WARN: 'Could not find HammerJS. Certain Angular Material components may not work correctly.'

From from Angular Material Getting Started Guide : 从《 Angular Material入门指南》中

Some components ( md-slide-toggle , md-slider , mdTooltip ) rely on HammerJS for gestures. 一些组件( md-slide-togglemd-slidermdTooltip )依靠HammerJS进行手势。 In order to get the full feature-set of these components, HammerJS must be loaded into the application. 为了获得这些组件的完整功能集,必须将HammerJS加载到应用程序中。

Based on that, my conclusion is that I don't need HammerJS installed as I'm not specifically using the Angular Material components that require it. 基于此,我的结论是我不需要安装HammerJS,因为我没有专门使用需要它的Angular Material组件。 If you don't need it, don't add it! 如果您不需要它,请不要添加它!

But whilst executing 1000+ tests, having that warning print out each time really isn't helpful and so I want to get rid of it or have it print once only. 但是,尽管执行了1000多个测试,但每次都打印出该警告确实没有帮助,因此我想摆脱它或只打印一次。

The following solution will: 以下解决方案将:

  1. Warn about the lack of HammerJS once only. 仅警告一次缺少HammerJS。
  2. Print an error to the console if you ever end up using the new Hammer() constructor in the future. 如果将来最终使用new Hammer()构造函数,则将错误输出到控制台。
  3. Not require you to call enableProdMode() within your test environment so you can continue to benefit from the additional error checking that double change detection provides. 不需要您在测试环境中调用enableProdMode() ,因此您可以继续受益于双重更改检测提供的其他错误检查。

Add the following beforeAll function to your test bundle: 将以下beforeAll函数添加到测试包中:

beforeAll(function() {
    if (!window.hasOwnProperty('Hammer')) {
        window['Hammer'] = function() {
            console.error(
                'HammerJS is not installed. If you\'re now using Angular Material components that require it, please "npm i hammerjs"'
            );
        };
        console.warn('Could not find HammerJS. Certain Angular Material components may not work correctly.');
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM