Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/120.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 为什么酶测试在React.js中不起作用?_Reactjs_Enzyme - Fatal编程技术网

Reactjs 为什么酶测试在React.js中不起作用?

Reactjs 为什么酶测试在React.js中不起作用?,reactjs,enzyme,Reactjs,Enzyme,我在CreateReact应用程序中使用酶测试。在shallow渲染中,它可以正常工作,但mount渲染会引发错误: TypeError:无法读取未定义的属性“收藏夹” 测试文件如下所示: import React, { Component } from "react"; import configureMockStore from "redux-mock-store"; import { shallow, mount } from "enzyme"; import { Provider } f

我在CreateReact应用程序中使用酶测试。在
shallow
渲染中,它可以正常工作,但
mount
渲染会引发错误:

TypeError:无法读取未定义的属性“收藏夹”

测试文件如下所示:

import React, { Component } from "react";
import configureMockStore from "redux-mock-store";
import { shallow, mount } from "enzyme";
import { Provider } from "react-redux";
import Favorites from "../Landing/Favorites";

const mockStore = configureMockStore();
const store = mockStore({});

function setup() {
  const props = {
    favorites: 42
  };
  const wrapper = mount(
    <Provider store={store}>
      <Favorites {...props} />
    </Provider>
  );
  return {
    props,
    wrapper
  };
}

describe("Favorites component", () => {
  const { wrapper } = setup();
  it("should render list of favorites cards", () => {
    expect(wrapper.prop("favorites")).toEqual(42);
  });
});
import React,{Component}来自“React”;
从“redux模拟存储”导入configureMockStore;
从“酶”中导入{shall,mount};
从“react redux”导入{Provider};
从“./Landing/Favorites”导入收藏夹;
const mockStore=configureMockStore();
const store=mockStore({});
函数设置(){
常量道具={
最爱:42
};
常量包装器=装入(
);
返回{
道具,
包装纸
};
}
描述(“收藏夹组件”,()=>{
const{wrapper}=setup();
它(“应该呈现收藏卡列表”,()=>{
expect(wrapper.prop(“favorites”).toEqual(42);
});
});

为什么会发生这种情况?

.prop
的安装和安装方式不同。你可以查看文件。

使用
mount
时,可以直接渲染收藏夹组件。
mount()

您必须执行wrapper.props().favorites,否?不幸的是,它会引发相同的错误。能否向我们提供“wrapper.debug()”的输出?谢谢,但在这种情况下会引发另一个错误:
不变冲突:在“Connect(favorites)”的上下文或道具中找不到“store”。将根组件包装在中,或者将“存储”作为道具显式传递给“连接(收藏夹)”。