Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Simple test helper for testing recompose HOCs
import React from 'react'
import { mount } from 'enzyme'
const render = ({ hoc, data, context }) => {
const Component = () => <div />
const WrappedComponent = hoc(Component)
return mount(<WrappedComponent {} />, { context })
// By default, return the 'inner', wrapped component.
export default (hoc, data, context) =>
render({ hoc, data, context }).find('Component')
// to test state updates we need to return the component and the update method
export const renderHOCWithStateUpdate = (hoc, data, context) => {
const component = render({ hoc, data, context })
const update = () => {
return component.find('Component')
return {
component: component.find('Component'),
root: component,
// Usage
import renderHOC, {renderHOCWithStateUpdate} from './utils/renderHOC'
// simple case without setState
const component = renderHOC({hoc: someHOC, data:{some:'data'}})
// case without setState
const wrapper = renderHOCWithStateUpdate({hoc: someHOC, data:{some:'data'}})
let component = wrapper.component
let update = wrapper.update
component = update()

This comment has been minimized.

Copy link
Owner Author

@eskimoblood eskimoblood commented Jan 11, 2019

The main idea is to render HOCs independently from real views, by using just a simple dummy component and only test that the props passed to the dummy are correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.