mercredi 10 février 2016

How to test for a `click` event on the icon button of the `material-ui` AppBar?

I'm testing the following React component:

import React from 'react'
import AppBar from 'material-ui/lib/app-bar'

class NavBar extends React.Component {
  render () {
    return (
      <div>
        <AppBar
          title='My NavBar Title'
        />
      </div>
    )
  }
}

export default NavBar

It's composed of a material-ui AppBar component. Using Tape and Enzyme, I want to simulate a click on the AppBar's IconButton:

import NavBar from './NavBar'
import React from 'react'
import test from 'tape'
import { /* I don't know if it's `shallow` or `mount` */ } from 'enzyme'

test('NavBar component test', (assert) => {
  test('simulating a click on the icon button', (assert) =>
    // How do I do this?
    // The following results in error:
    // const wrapper = shallow(<NavBar />)
    // wrapper.find('AppBar').find('IconButton').simulate('click')
    assert.end()
  })
  assert.end()
})

How can I do it properly?

Obs: I'm searching for IconButton because, according to the React Dev Tools tab, that's the name of the rendered icon button component.

Aucun commentaire:

Enregistrer un commentaire