2018-01-31 07:36:20 +00:00
|
|
|
/* eslint-env jest */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Individual component testing is pretty simple
|
|
|
|
* just provide your dependencies as props
|
|
|
|
* and add `.dive()` step to your shallow render,
|
|
|
|
* as with any High Order Component.
|
|
|
|
*
|
|
|
|
* Remarks about `.html()` may apply,
|
|
|
|
* depending if any of the children components
|
|
|
|
* expect anything from the context
|
|
|
|
*/
|
|
|
|
|
|
|
|
import { shallow } from 'enzyme'
|
|
|
|
import React from 'react'
|
|
|
|
import renderer from 'react-test-renderer'
|
|
|
|
|
|
|
|
import Component from '../components/endpoint.js'
|
|
|
|
|
|
|
|
describe('With Enzyme', () => {
|
|
|
|
it('Component renders with props', () => {
|
|
|
|
// no need to mock Link component much for shallow rendering
|
|
|
|
const injected = shallow(<Component Link={() => {}} />)
|
|
|
|
const component = injected.dive()
|
|
|
|
expect(component.find('h3').text()).toEqual('Endpoint')
|
2018-12-17 16:34:32 +00:00
|
|
|
expect(
|
|
|
|
component
|
|
|
|
.find('Link')
|
|
|
|
.first()
|
|
|
|
.find('a')
|
|
|
|
.text()
|
|
|
|
).toEqual('About: foo baz')
|
2018-01-31 07:36:20 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('With Snapshot Testing', () => {
|
|
|
|
it('Blog renders components', () => {
|
2018-12-17 16:34:32 +00:00
|
|
|
const component = renderer.create(
|
|
|
|
<Component
|
|
|
|
Link={props => (
|
|
|
|
<div comment={'mocked Link component'}>{props.children}</div>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
)
|
2018-01-31 07:36:20 +00:00
|
|
|
const tree = component.toJSON()
|
|
|
|
expect(tree).toMatchSnapshot()
|
|
|
|
})
|
|
|
|
})
|