Skip to content

Commit

Permalink
Merge pull request #4 from santino/fix_hooks
Browse files Browse the repository at this point in the history
Fix for React hooks
  • Loading branch information
santino authored Jul 15, 2021
2 parents 90b036f + 114650a commit 29fb7f1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
4 changes: 1 addition & 3 deletions src/NavigationListener.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react'
import PropTypes from 'prop-types'
import { action } from '@storybook/addon-actions'
import { linkTo } from '@storybook/addon-links'
import { routerShape } from 'found/PropTypes'
Expand Down Expand Up @@ -62,12 +61,11 @@ class NavigationListener extends React.Component {
}

render () {
return this.props.story()
return <>{this.props.children}</>
}
}

NavigationListener.propTypes = {
story: PropTypes.func.isRequired,
router: routerShape.isRequired
}

Expand Down
8 changes: 4 additions & 4 deletions src/NavigationListener.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { mount, shallow } from 'enzyme'
import { mount } from 'enzyme'
import { action } from '@storybook/addon-actions'
import { linkTo } from '@storybook/addon-links'
import NavigationListener from './NavigationListener'
Expand Down Expand Up @@ -39,18 +39,18 @@ describe('NavigationListener', () => {
}
}
const wrap = () =>
mount(<NavigationListener {...routerProp} story={storyFn} />)
mount(<NavigationListener {...routerProp}>{storyFn()}</NavigationListener>)

describe('React Component', () => {
afterEach(() => {
routerProp.router.addNavigationListener.mockClear()
})

it('renders the passed story element as a children', () => {
it('renders children component (story) correctly', () => {
const wrapper = wrap()

expect(wrapper.find('NavigationListener')).toHaveLength(1)
expect(wrapper.children().html()).toEqual(shallow(storyFn()).html())
expect(wrapper.children().equals(storyFn())).toBe(true)
})

it('adds the internal onNavigation method as a NavigationListener', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const storyRouterDecorator = (routes = [{}], initialLocation = '') => {
path: rootPath,
Component: NavigationListener,
render: ({ Component, props }) => (
<Component {...props} story={story} />
<Component {...props}>{story()}</Component>
),
children: routes.map(normaliseRouteChildren)
}
Expand Down

0 comments on commit 29fb7f1

Please sign in to comment.