Skip to content

Instantly share code, notes, and snippets.

@lai32290
Last active September 23, 2020 21:27
Show Gist options
  • Save lai32290/b882dc35dc219b23e1feded30782bed1 to your computer and use it in GitHub Desktop.
Save lai32290/b882dc35dc219b23e1feded30782bed1 to your computer and use it in GitHub Desktop.
// __tests__/accordion.enzyme.js
import React from 'react'
// if you're wondering why not shallow,
// then please read <https://kcd.im/shallow>
import Enzyme, {mount} from 'enzyme'
import EnzymeAdapter from 'enzyme-adapter-react-16'
import Accordion from '../accordion'
// Setup enzyme's react adapter
Enzyme.configure({adapter: new EnzymeAdapter()})
test('setOpenIndex sets the open index state properly', () => {
const wrapper = mount(<Accordion items={[]} />)
expect(wrapper.state('openIndex')).toBe(0)
wrapper.instance().setOpenIndex(1)
expect(wrapper.state('openIndex')).toBe(1)
})
test('Accordion renders AccordionContents with the item contents', () => {
const hats = {title: 'Favorite Hats', contents: 'Fedoras are classy'}
const footware = {
title: 'Favorite Footware',
contents: 'Flipflops are the best',
}
const wrapper = mount(<Accordion items={[hats, footware]} />)
expect(wrapper.find('AccordionContents').props().children).toBe(hats.contents)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment