简体   繁体   English

如何用 jest 和 enzyme 使用 Relay modern 进行测试?

[英]How to do testing with Relay modern with jest and enzyme?

How to test this kind of file with jest and enzyme...如何用 jest 和 enzyme 测试这种文件...

 class App extends React.Component{ constructor(){ super() } render(){ const { viewer, children, isLoading } = this.props return( <div> <div id="container"> {children} </div> {isLoading && <Loading />} </div> ); } } export default createFragmentContainer( App, graphql` fragment App_viewer on User{ id email } ` )

You can do something like this你可以这样做

const React = require('React');
const App = require('App.react');
jest.mock('react-relay', () => ({
  createFragmentContainer: App =>
    App,
}));

const {shallow} = require('enzyme');
const {shallowToJson} = require('enzyme-to-json');

describe('App', () => {
  it('renders the dashboard section correctly', () => {
    const wrapper = shallow(
      < App
        title="Test Dashboard Section"
        charts={[]}
      />,
    );
    expect(shallowToJson(wrapper)).toMatchSnapshot();
  });

We need to mock react-relay.我们需要模拟 react-relay。 As mentioned above.正如刚才提到的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM