Jest的material-ui Dialog组件测试问题

时间:2018-07-12 14:51:26

标签: testing dialog jestjs material-ui

测试:

Enzyme.configure({ adapter: new Adapter() });

function setup(initialState) {
    const store = configureStore(initialState);
    const history = createBrowserHistory();
    const provider = (
        <MuiThemeProvider>
            <Provider store={store}>
                <ConnectedRouter history={history}>
                    <ThemeProvider theme={Theme}>
                            <Modal isModalOpen={true}/>
                    </ThemeProvider>
                </ConnectedRouter>
            </Provider>
        </MuiThemeProvider>
    );
    const app = mount(provider);
    return {
        app,
        inputs: app.find('input'),
    };
}

describe('containers', () => {
    describe('App', () => {
        it('inputs count should be equal 3', () => {
            const { inputs } = setup();
            expect(inputs.length).toEqual(3);
        });
    });
});

当我运行测试时,它应该返回输入计数= 3但返回0。似乎输入不可见。当我将Dialog更改为普通div时,一切正常。

测试组件:

return (
      <Dialog
        modal
        open={true}
      >
        <TextField/>

        <TextField/>

        <TextField/>
      </Dialog>
    );

0 个答案:

没有答案