超级表达式必须为null或函数,而不是未定义

时间:2017-11-13 18:32:39

标签: reactjs jestjs enzyme

我尝试使用Enzyme为以下React组件配置Jest:

import React from "react";
import PropTypes from "prop-types";

class App extends React.PureComponent {
    render() {
        return (
            <section className='container-menu'>
                <div className='item-logo'>
                    <img width='70' src='/images/logo.png'/>
                </div>
                <div className='item-menu'>
                    {/*<AppMenu/>*/}
                </div>
                <div className='item-page-header'>
                    {this.props.children}
                </div>
            </section>
        );
    }
}

export default App;

根据http://airbnb.io/enzyme/docs/installation/react-15.html,配置酶在Jest中运行的方法是根据以下测试代码:

import App from "./App";
import React from "react";
import {configure, shallow} from 'enzyme';
import Adapter from 'enzyme-adapter-react-15';

describe("App", () => {
    configure({adapter: new Adapter()});
    const wrapper = shallow(<App/>);
    expect(wrapper.exists()).toBe(true);
});

当我运行测试运行器时,我收到以下错误:

TypeError:超级表达式必须为null或函数,而不是未定义

  at _inherits (node_modules/enzyme-adapter-react-15/build/ReactFifteenAdapter.js:51:113)
  at node_modules/enzyme-adapter-react-15/build/ReactFifteenAdapter.js:135:3
  at Object.<anonymous> (node_modules/enzyme-adapter-react-15/build/ReactFifteenAdapter.js:400:2)
  at Object.<anonymous> (node_modules/enzyme-adapter-react-15/build/index.js:2:18)
  at Object.<anonymous> (src/app/view/App.test.js:4:27)
  at next (native)
  at handle (node_modules/worker-farm/lib/child/index.js:44:8)
  at process.<anonymous> (node_modules/worker-farm/lib/child/index.js:51:3)
  at emitTwo (events.js:106:13)
  at process.emit (events.js:191:7)
  at process.nextTick (internal/child_process.js:719:12)
  at _combinedTickCallback (internal/process/next_tick.js:67:7)
  at process._tickCallback (internal/process/next_tick.js:98:9)

1 个答案:

答案 0 :(得分:2)

我有同样的问题。然后结果表明,ases-adapter-react-15也取决于ases@3.x.x

我通过运行npm i --save-dev enzyme@latest解决了这个问题。

您可以查看此问题以获取更多信息:https://github.com/airbnb/enzyme/issues/1172