1import Enzyme from 'enzyme';
2import Adapter from 'enzyme-adapter-react-16';
3
4Enzyme.configure({ adapter: new Adapter() });
5
1// global config react and enzyme
2
3import { configure } from 'enzyme'
4import Adapter from 'enzyme-adapter-react-16'
5import { shallow, mount, render } from 'enzyme'
6import renderer from 'react-test-renderer'
7
8configure({ adapter: new Adapter() })
9
10global.shallow = shallow
11global.mount = mount
12global.render = render
13global.renderer = renderer
1// dom.js
2
3import React from 'react'
4
5const DomTest = () => (
6 <div>
7 <div className='parentSatu'>
8 <p className='childSatu'>hello wordl satu</p>
9 </div>
10 <div className='parentDua'>
11 <p className='childDua'>hello wordl dua</p>
12 </div>
13 <div className='parentTiga'>
14 <p className='childTiga'>hello wordl tiga</p>
15 </div>
16
17 <div className='domGroup'>
18 <p className='domSatu satu'>DOM Satu</p>
19 <p className='domDua'>DOM Dua</p>
20 <p className='domTiga'>DOM Tiga</p>
21 </div>
22
23 <h1 className='header'>
24 <span className='sub-header'>Hello World</span>
25 </h1>
26 </div>
27)
28
29export default DomTest
30
31// dom.test.js
32
33test('find element in DomTest Component by index using at', () => {
34 expect(wrapper.find('.domGroup').children().at(0).text()).toStrictEqual('DOM Satu')
35 expect(wrapper.find('.domGroup').children().at(1).text()).toStrictEqual('DOM Dua')
36 expect(wrapper.find('.domGroup').children().at(2).text()).toStrictEqual('DOM Tiga')
37 })