如何测试将商店与酶一起使用的组件?

时间:2019-05-02 16:49:37

标签: reactjs redux enzyme

我正在尝试弄清楚如何模拟<Provider>进行测试,

这是我正在测试的组件:

const Auth = props => {
  const responseGoogle = ({ tokenId }) => {
    props.signToken(tokenId);
  };
  return (
    <div className="authContainer">
      <Logo logoClass="logo" />
      <GoogleLogin
        clientId="550277865980-r6bp701c5lpadsn07rk3uk31javee7k0.apps.googleusercontent.com"
        icon={false}
        onSuccess={responseGoogle}
        className="googleButton"
      >
        <Button />
      </GoogleLogin>
    </div>
  );
};

现在,我只想测试它是否呈现徽标组件。

import React from 'react';
import { shallow } from 'enzyme';
import configureStore from 'redux-mock-store';
import Auth from '../../Auth/index';
import '../../../setupTests';

describe('Auth Component', () => {
  it('renders the logo', () => {
    const wrapper = shallow(<Auth />);
    console.log(wrapper);
  });
});

我遇到以下错误:

Invariant Violation: Could not find "store" in the context of 
"Connect(Auth)". Either wrap the root component in a <Provider>, or 
pass a custom React context provider to <Provider> and the 
corresponding React context consumer to Connect(Auth) in connect options.

0 个答案:

没有答案