Render()模态测试Jest酶

时间:2019-02-01 18:23:08

标签: reactjs unit-testing jestjs enzyme

我并不是真的如何测试render()模态。我能够设置道具并测试Render()“确保它正确地使用所有道具进行渲染”而没有任何问题。 但是当涉及到渲染模态时-我可能会丢失一些东西

使用ReactJS 15-开胃酶VSC

it(' Should render with all of the props ', () => {  
tree = renderer.create(<Component {...baseProps} />)
let treeJson = tree.toJSON()
expect(treeJson).toMatchSnapshot();
tree.unmount()
 });

我在网上找到了此文件,但尝试对其进行测试,但我相信可能缺少某些内容。有什么想法吗?

it('renders correctly', () => {
const wrapper = mount( <Component modalOpen/> );
expect(wrapper).toMatchSnapshot();
// Passes
expect(wrapper.find('.outside')).toHaveLength(1);
// Construct new wrapper rooted at modal content
inside_els = document.getElementsByClassName("inside")[0]
inside_wrapper = new ReactWrapper(inside_els, true)

// Passes
expect(inside_wrapper.find('.inside')).toHaveLength(1);

这是render()Modal的示例

 render() {
   //console.log(this.props)
   return (
  <Modal isOpen={this.props.isOpen} style={modalStyle}>
    <div className='security-search-wrapper-modal'>
      <div className='fullmodal'> 
        <div className='fullmodal_title'>Batch Update</div>
        <div title="Close Window" className="add-custom-field-close" 
onClick={() => {this.closeModal()}}><FontAwesome name='xbutton' 
className='fa-times' /></div>
      </div>

1 个答案:

答案 0 :(得分:0)

经过一番研究:我找到了:

https://github.com/reactjs/react-modal/issues/563

随时发表评论

相关问题