lundi 2 mars 2020

Failed to parse selector Enzyme React

I'm testing with Enzyme and Jest my react app. I have a some elements with a lot of white spaces in their ids string and they have to be in html ids, so I replace them with '-'. But when I run my test I have an error:

Error: Failed to parse selector: tr#28000010785600108---------BA---------

I thought middle dashed were allowed in html ids and classes.

Here is my code:

    describe('VerticalBox', () => {
          const verticals = [
            {'id':'28000010785600108         BA         ', 'bisDuplicate':null, 'block':null, 'door':null, 'letter':null, 'stair':null, 'floor':'Bajo', 'hand1':null, 'hand2':null, 'summary':'Bajo'},
            {'id':'28000010785600108       W BA         ', 'bisDuplicate':null, 'block':null, 'door':null, 'letter':null, 'stair':'Derecha', 'floor':'Bajo', 'hand1':null, 'hand2':null, 'summary':'Derecha Bajo'}
    ]

    const defaultProps = {
        className: 'erwfw',
        verticals: verticals,
      }

    const component = (
        <VerticalBox
          {...defaultProps}
        />
      )

      const wrapper = mount(component)

    it('onSelect events', () => {
        wrapper.find('tr#' + verticals[0].id.replace(/ /g, '-')).simulate('click')
    expect(.......)
    })
})

My component returns:

return (
    <div className={className}>
      <table cellSpacing="0" cellPadding="0" className={'vertical-table'}>
        <thead>
          <tr>
            <th></th>
            <th>Piso</th>

          </tr>
        </thead>
        <tbody>
          {
            verticals.map((vertical) => (
              <tr key={vertical.id} id={vertical.id && vertical.id.replace(/ /g, '-')} className={vertical.id === selectedIndex ? 'selected' : ''} onClick={() => onSelectRow(`${vertical.id}.`)}>
                <td className={'radio-container'}>
                  <MaterialRadio
                    value={`${vertical.id}.`}
                    text={''}
                    onSelect={() => {}}
                    checked={ vertical.id === selectedIndex} />
                </td>
                <td>{`${vertical.floor} ${vertical.hand1 || ''}`}</td>
              </tr>
            ))
          }
        </tbody>
      </table>
    </div>
  )

Aucun commentaire:

Enregistrer un commentaire