本文介绍了反应+酶错误:不断违反:危险RenderMarkup(...):无法在工作线程中呈现标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用酶测试反应组件,但出现以下错误:

I am testing a react component using Enzyme and I'm getting the following error:

我在需要'酶'之前为jsdom添加了以下设置(正如我读过的):

I added the following setup for jsdom, before requiring 'enzyme' (as I read in few places):

const baseMarkup = '<!DOCTYPE html><html><head><title></title></head><body></body></html>';
const window = require('jsdom').jsdom(baseMarkup).defaultView;

global.window = window;
global.document = window.document;
global.navigator = window.navigator;

const React = require('react');
const {mount} = require('enzyme');
const sinon = require('sinon');
const SortableInput = require('../../../src/components/sortableInput/sortableInput').default;

我在这里做什么错了?

编辑

我认为这与服务器端渲染无关。该消息是有关单元测试和服务器端渲染的常规消息。

I don't think it is related to server side rendering. The message is general about unit testing and server side rendering.

推荐答案

回答我自己的问题,以防有人遇到相同的问题。这最终对我有用:

Answering my own question, in case someone have the same issue. This was what eventually worked for me:

import 'jsdom-global/register';

describe('My awesome component test', () => {
  let cleanup;

  beforeEach(() => cleanup = require('jsdom-global')());

  afterEach(() => cleanup());

  ....
})

这篇关于反应+酶错误:不断违反:危险RenderMarkup(...):无法在工作线程中呈现标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-25 05:13