enzymejs inject child component code example

Example: enzyme childAt example

// dom.js

import React from 'react'

const DomTest = () => (
  <div>
    <div className='domGroup'>
      <p className='domSatu satu'>DOM Satu</p>
      <p className='domDua'>DOM Dua</p>
      <p className='domTiga'>DOM Tiga</p>
    </div>
  </div>
)

export default DomTest

// dom.test.js
test('find element in DomTest Component by index using childAt', () => {
  expect(wrapper.find('.domGroup').childAt(0).text()).toStrictEqual('DOM Satu')
  expect(wrapper.find('.domGroup').childAt(1).text()).toStrictEqual('DOM Dua')
  expect(wrapper.find('.domGroup').childAt(2).text()).toStrictEqual('DOM Tiga')
})