首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >React与cucumberjs的集成

React与cucumberjs的集成
EN

Stack Overflow用户
提问于 2017-06-22 02:41:55
回答 1查看 2.4K关注 0票数 2

我正在做一个React-Nextjs项目,并试图集成BDD工具cucumber进行规范和功能级测试。虽然我在使用enzyme进行浅层渲染组件时遇到了一些cucumber和React的集成问题:

下面是我收到的错误:const wrapper = shallow(<Referrer/>);上的TypeError: Cannot read property 'contextTypes' of undefined

cucumber步骤测试文件代码:

代码语言:javascript
复制
import React from 'react';
import { defineSupportCode } from "cucumber";
import { shallow } from "enzyme";
import {Referrer} from "./../../components/Referrer";

defineSupportCode(({ Given, When, Then }) => {
    Given("I want to do something", function (callback) {
        // Write code here that turns the phrase above into concrete actions
        callback();
    });

    When("Xyz link is clicked", function (callback) {
        const wrapper = shallow(<Referrer/>);
        ... // Write code here that turns the phrase above into concrete actions
    });

    Then("Appropriate action happens", function (callback) {
        // Write code here that turns the phrase above into concrete actions
        callback();
    });
});

这个组件是一个简单的UI组件,非常简单,下面是它的结构:

代码语言:javascript
复制
import React from "react"; // eslint-disable-line no-unused-vars

export default class Referrer extends React.Component {
    render () {
        return (
            <div className="some-class" id="some-id">
              // html tags
              <style jsx>{`
                .some-class {
                  //styling
                }

                .some-class2 {
                  //styling
                }
              `}
              </style>
            </div>
        );
    }
}

我正在使用"cucumber": "^2.3.1""enzyme": "^2.6.0",我不确定如何解决这个问题,到目前为止在网上没有帮助,我已经试着调试了几个小时,但没有运气。

确切的错误片段:

代码语言:javascript
复制
Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in.

const wrapper = shallow(<Referrer/>);上的TypeError: Cannot read property 'contextTypes' of undefined

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-06-23 05:04:31

我意识到问题出在哪里,我的Referrer组件被默认导出,尽管我没有正确地导入它。我不得不将其导入为import Referrer from "./../../components/Referrer";而不是import {Referrer} from "./../../components/Referrer";

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44683865

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档