enzyme testing
import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
Enzyme.configure({ adapter: new Adapter() });
4.14
7
// dom.js
import React from 'react'
const DomTest = () => (
<div>
<div className='parentSatu'>
<p className='childSatu'>hello wordl satu</p>
</div>
<div className='parentDua'>
<p className='childDua'>hello wordl dua</p>
</div>
<div className='parentTiga'>
<p className='childTiga'>hello wordl tiga</p>
</div>
<div className='domGroup'>
<p className='domSatu satu'>DOM Satu</p>
<p className='domDua'>DOM Dua</p>
<p className='domTiga'>DOM Tiga</p>
</div>
<h1 className='header'>
<span className='sub-header'>Hello World</span>
</h1>
</div>
)
export default DomTest
// dom.test.js
test('find element in DomTest Component by index using at', () => {
expect(wrapper.find('.domGroup').children().at(0).text()).toStrictEqual('DOM Satu')
expect(wrapper.find('.domGroup').children().at(1).text()).toStrictEqual('DOM Dua')
expect(wrapper.find('.domGroup').children().at(2).text()).toStrictEqual('DOM Tiga')
})
Thank you!
7
0
3.5
2
hmmm tasty
Thank you!
2
0
4.2
10
npm i --save-dev enzyme enzyme-adapter-react-16
Thank you!
10
0
4
4
// global config react and enzyme
import { configure } from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'
import { shallow, mount, render } from 'enzyme'
import renderer from 'react-test-renderer'
configure({ adapter: new Adapter() })
global.shallow = shallow
global.mount = mount
global.render = render
global.renderer = renderer
Thank you!
4
0
4
5
const wrapper = shallow(<Button />);
wrapper.instance().handleClick()
Thank you!
5
0
Are there any code examples left?
New code examples in category Javascript