enzyme testing code example
Example 1: enzyme react
import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
Enzyme.configure({ adapter: new Adapter() });
Example 2: react enzyme
// 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
Example 3: enzyme test method
const wrapper = shallow();
wrapper.instance().handleClick()
Example 4: enzyme testing
npm i --save-dev enzyme enzyme-adapter-react-16
Example 5: enzyme at example
// dom.js
import React from 'react'
const DomTest = () => (
hello wordl satu
hello wordl dua
hello wordl tiga
DOM Satu
DOM Dua
DOM Tiga
Hello World
)
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')
})