【问题标题】:Render() Modal test Jest EnzymeRender() 模态测试 Jest Enzyme
【发布时间】:2019-02-01 18:23:07
【问题描述】:

我并不是真的如何测试 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() 模态的例子

 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>

【问题讨论】:

    标签: reactjs unit-testing jestjs enzyme


    【解决方案1】:

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

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

    欢迎评论

    【讨论】:

      猜你喜欢
      • 2018-09-14
      • 2018-12-16
      • 2018-04-25
      • 2023-03-06
      • 2019-01-29
      • 1970-01-01
      • 2019-07-28
      • 2018-09-08
      • 2017-02-12
      相关资源
      最近更新 更多