Skip to content

Commit

Permalink
Merge pull request #133 from Patreon/proptypes
Browse files Browse the repository at this point in the history
Fix propTypes warning
  • Loading branch information
phou-patreon committed Feb 11, 2022
2 parents dc5f77f + c273abc commit f63b470
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@
],
"testMatch": [
"**/src/**/__tests__/**/*.[jt]s?(x)",
"**/src/**/?(*.)+(spec|test).[jt]s?(x)"
"**/src/**/?(*.)+(spec|test).[jt]s?(x)",
"**/test/**?(*.)+(spec|test).[jt]s?(x)"
],
"transform": {
"\\.js$": "babel-jest"
Expand Down
7 changes: 7 additions & 0 deletions src/decorator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,13 @@ const nion = (declarations = {}, ...rest) => WrappedComponent => {
).map(key => {
connectedComponent[key] = WrappedComponent[key]
})
// Remove nion from the propTypes of the connected component, if it exists,
// since it will be injected by withNion
if (connectedComponent.propTypes) {
const { nion: _, ...restProps } = connectedComponent.propTypes
connectedComponent.propTypes = restProps
}

return connectedComponent
}

Expand Down
49 changes: 49 additions & 0 deletions src/decorator/test/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import nion from '../'
import React from 'react'
import PropTypes from 'prop-types'
import { mount } from 'enzyme'

import { Provider } from 'react-redux'
import configureTestStore from '../../../test/configure-test-store'

describe('nion', () => {
describe('propTypes validation', () => {
let OuterComponent
let originalConsoleError
let store

beforeAll(() => {
originalConsoleError = global.console.error
// Treat all console.errors as test failures to catch failed propType validation
global.console.error = (...args) => {
throw new Error(args[0])
}
})

afterAll(() => {
global.console.error = originalConsoleError
})

beforeEach(() => {
class WrappedComponent extends React.Component {
static propTypes = {
nion: PropTypes.object.isRequired,
}

render() {
return null
}
}
OuterComponent = nion()(WrappedComponent)
store = configureTestStore()
})

it('has no propTypes errors', () => {
mount(
<Provider store={store}>
<OuterComponent />
</Provider>,
)
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
extrasAreEqual,
extensionsAreEqual,
dataAreEqual,
} from './should-rerender.js'
} from '../should-rerender.js'

const makeDataObject = (data = {}) => {
return Immutable({ type: 'test', id: '123', ...data })
Expand Down

0 comments on commit f63b470

Please sign in to comment.