测试工具中的警告

测试工具中的警告

本文介绍了如何禁用“检测到全局错误处理程序"vue 测试工具中的警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 vue-test-utilsjest 使用此处描述的方法创建异步测试:

I'm creating async tests using vue-test-utils and jest using the approach described here:

https://vue-test-utils.vuejs.org/guides/#what-about-nexttick

你在哪里设置 Vue.config.errorHandler = done 如下所示

where you set Vue.config.errorHandler = done like shown below

  test('Then we are shown events in EventCreate component', done => {
    Vue.config.errorHandler = done

这是有效的,当组件中的 Promise 处理程序抛出错误时,我的测试将失败.但是我收到了这个警告.

This is working and when an error is thrown in a promise handler in a component my tests will fail. However I'm getting this warning.

    console.error node_modules/@vue/test-utils/dist/vue-test-utils.js:1421
      [vue-test-utils]: Global error handler detected (Vue.config.errorHandler).
      Vue Test Utils sets a custom error handler to throw errors thrown by instances. If you want this behavior in your tests, you must remove the global error handler.

我不想用这个警告向我的测试输出发送垃圾邮件.有没有办法禁用它?

I don't want to spam my test output with this warning. Is there a way to disable it?

推荐答案

我就是这样做的

beforeEach(() => {
  jest.spyOn(console, 'error');
  console.error.mockImplementation(() => 'some error');
        });
afterEach(() => {
  console.error.mockRestore();
});

这篇关于如何禁用“检测到全局错误处理程序"vue 测试工具中的警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 05:11