如何通过玩笑和酵素对Relay Modern进行测试?

问题描述 投票:1回答:1

如何用笑话和酶测试这种文件...

   

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   
        }
    `
)
reactjs graphql jestjs enzyme relaymodern
1个回答
0
投票

您可以做这样的事情

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();
  });

我们需要模拟react-relay。正如刚才提到的。

© www.soinside.com 2019 - 2024. All rights reserved.