enzymejs/enzyme

configure custom wrappingComponent and use shallow method cause RangeError: Maximum call stack size exceeded

開放

#2,309 建立於 2019年12月25日

 (5 則留言) (0 個反應) (0 位負責人)JavaScript (1,967 個分叉)batch import
API: shallowbughelp wanted

倉庫指標

星標
 (19,826 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

Jest setup file:

import React from 'react';
import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';

function CustomWrapper({ children }) {
  return <div>{children}</div>;
}

configure({
  adapter: new Adapter(),
  wrappingComponent: CustomWrapper,
});

Test case:

import React from 'react';
import { shallow } from 'enzyme';

function Button() {
  return <button>My Button</button>;
}

it('should work', function () {
  const el = shallow(<Button />); // throw RangeError: Maximum call stack size exceeded
  expect(el).toMatchSnapshot();
});

I found it seems to be this line: ShallowWrapper.js#L355

  • enzyme: 3.10.0
  • enzyme-adapter-react-16: 1.15.1
  • jest: 24.9.0
  • react: 16.12.0

貢獻者指南