Skip to content

enzyme@3: wrapper is not updated even if there was a new render #1153

@deepsweet

Description

@deepsweet

Hi. Just faced this after updating to v3.

Given the following deps:

├─ enzyme-adapter-react-16@1.0.0
├─ enzyme@3.0.0
├─ react-dom@16.0.0
├─ react-test-renderer@16.0.0
└─ react@16.0.0

And the HOC:

import React, { Component } from 'react'

const testHOC = (Target) => class TestClass extends Component {
  constructor (...args) {
    super(...args)

    this.state = {}
    this.onTest = this.onTest.bind(this)
  }

  onTest () {
    this.setState({
      foo: true
    })
  }

  render () {
    console.log(this.state)

    return (
      <Target {...this.props} {...this.state} onTest={this.onTest} />
    )
  }
}

export default testHOC

And the test:

import React from 'react'
import { mount } from 'enzyme'
import testHOC from './testHOC'

describe('testHOC', () => {
  it('should work', () => {
    const Target = () => null
    const EnhancedTarget = testHOC(Target)
    const wrapper = mount(
      <EnhancedTarget />
    )

    wrapper.find(Target).prop('onTest')()

    console.log(
      wrapper.debug()
    )
  })
})

I see:

  console.log testHOC.js:18
    { foo: true }

  console.log testHOC.spec.js:15
    <TestClass>
      <Target onTest={[Function]} />
    </TestClass>

So the was a new render, but wrapper just didn't react to it. Works fine with v2.

Please correct me if I was wrong all this time and test should be written in another way.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions