簡體   English   中英

如何用 jest 和 enzyme 使用 Relay modern 進行測試?

[英]How to do testing with Relay modern 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 } ` )

你可以這樣做

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。 正如剛才提到的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM