mui / material-ui

Material UI: Comprehensive React component library that implements Google's Material Design. Free forever.
https://mui.com/material-ui/
MIT License
93.37k stars 32.14k forks source link

Boolean properties breaks enzyme matchers #9318

Closed toppsdown closed 6 years ago

toppsdown commented 6 years ago

When attempting to detect a TextField in a test using containsMatchingElement, the detection failed. I narrowed it down to some issue with boolean properties.

Version: 0.19.4

Expected Behavior

Current Behavior

Steps to Reproduce (for bugs)

Here's the example code that is failing. I would expect both tests to pass, but only the first one does. ~I will move this code to codesandbox.io and add link~ Looks like codesandbox doesn't support running tests.

import React from 'react'
import { assert, expect } from 'chai'
import { shallow } from 'enzyme'

import TextField from 'material-ui/TextField'

// Successfully detect TextField
class TestComponent1 extends React.Component {
  render(){
    return (
      <TextField />
    )
  }
}

describe('<TestComponent1 />', function(){
  it('detects TextField', function(){
    const testComponentWrapper = shallow(<TestComponent1 />)

    assert.isTrue(testComponentWrapper.containsMatchingElement(<TextField />))
  })
})

// Fails to detect TextField
class TestComponent2 extends React.Component {
  render(){
    return (
      <TextField
        fullWidth={true}
      />
    )
  }
}

describe('<TestComponent2 />', function(){
  it('detects TextField', function(){
    const testComponentWrapper = shallow(<TestComponent2 />)

    assert.isTrue(testComponentWrapper.containsMatchingElement(<TextField />))
  })
})

Context

Trying to use best practice `containsMatchingElement(Element w/ Props)` instead of `find(Element).props()` ## Your Environment
Tech Version
Material-UI 0.19.4
React 15.6.2
enzyme 3.1.1
rosskevin commented 6 years ago

@toppy42 - 0.x is in maintenance mode and the core team is focused on the imminent 1.x release. We are happy to accept a PR for this!

oliviertassinari commented 6 years ago

@toppy42 as @rosskevin said, we have been porting the component on the v1-beta branch. We have reimplemented it from the ground-up.

We encourage people starting with Material-UI to go with v1-beta. The master branch is in a low maintenance mode. We don't plan any work on it. However, we still do our best to review and merge pull requests that fix bugs on this branch.