Skip to content

Commit c9f268e

Browse files
committed
fix renderCountProp, add a test
also clean up unused canary values
1 parent 5dfa621 commit c9f268e

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/components/connectAdvanced.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ export default function connectAdvanced(
164164
let derivedProps = this.memoizeDerivedProps(state, otherProps, store)
165165

166166
if (renderCountProp) {
167-
derivedProps = { ...derivedProps, renderCountProp: this.renderCount++ }
167+
derivedProps = { ...derivedProps, [renderCountProp]: this.renderCount++ }
168168
}
169169
if (connectOptions.pure) {
170170
return <PureWrapper {...derivedProps} forwardRef={forwardRef}/>

test/components/connect.spec.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2245,11 +2245,8 @@ describe('React', () => {
22452245
})
22462246

22472247
it('should error on receiving a custom store key', () => {
2248-
const store = createStore(() => ({}))
2249-
store.dispatch.mine = 'hi'
22502248
const connectOptions = { storeKey: 'customStoreKey' }
22512249

2252-
22532250
expect(() => {
22542251
@connect(undefined, undefined, undefined, connectOptions)
22552252
class Container extends Component {
@@ -2284,5 +2281,23 @@ describe('React', () => {
22842281
rtl.render(<Oops />)
22852282
}).toThrow(/passing redux store/)
22862283
})
2284+
2285+
it('should add a renderCount prop if specified in connect options', () => {
2286+
let value = 0
2287+
const store = createStore(() => ({ value: value++}))
2288+
function Comp(props) {
2289+
console.log(props)
2290+
return <div>{props.count}</div>
2291+
}
2292+
const Container = connect(undefined,undefined,undefined,{ renderCountProp: 'count' })(Comp)
2293+
const tester = rtl.render(
2294+
<ProviderMock store={store}>
2295+
<Container/>
2296+
</ProviderMock>
2297+
)
2298+
expect(tester.queryByText('0')).not.toBe(null)
2299+
store.dispatch({ type: 'hi' })
2300+
expect(tester.queryByText('1')).not.toBe(null)
2301+
})
22872302
})
22882303
})

0 commit comments

Comments
 (0)