Skip to content

Commit

Permalink
Add double-rendering test for immutable and seamless-immutable
Browse files Browse the repository at this point in the history
  • Loading branch information
supasate committed Dec 27, 2018
1 parent 0866442 commit c5eebfc
Showing 1 changed file with 113 additions and 1 deletion.
114 changes: 113 additions & 1 deletion test/ConnectedRouter.test.js
Expand Up @@ -178,7 +178,7 @@ describe('ConnectedRouter', () => {
history.push('/new-location')
expect(renderCount).toBe(2)
})
})
})

describe('with immutable structure', () => {
let ConnectedRouter
Expand Down Expand Up @@ -243,6 +243,62 @@ describe('ConnectedRouter', () => {

expect(onLocationChangedSpy.mock.calls).toHaveLength(3)
})

it('only renders one time when mounted', () => {
let renderCount = 0

const RenderCounter = () => {
renderCount++
return null
}

mount(
<Provider store={store}>
<ConnectedRouter {...props}>
<Route path="/" component={RenderCounter} />
</ConnectedRouter>
</Provider>
)

expect(renderCount).toBe(1)
})

it('does not render again when non-related action is fired', () => {
// Initialize the render counter variable
let renderCount = 0

// Create redux store with router state
store = createStore(
combineReducers({
incrementReducer: (state = 0, action = {}) => {
if (action.type === 'testAction')
return ++state

return state
},
router: connectRouter(history)
}),
compose(applyMiddleware(routerMiddleware(history)))
)


const RenderCounter = () => {
renderCount++
return null
}

mount(
<Provider store={store}>
<ConnectedRouter {...props}>
<Route path="/" component={RenderCounter} />
</ConnectedRouter>
</Provider>
)

store.dispatch({ type: 'testAction' })
history.push('/new-location')
expect(renderCount).toBe(2)
})
})

describe('with seamless immutable structure', () => {
Expand Down Expand Up @@ -290,6 +346,62 @@ describe('ConnectedRouter', () => {

expect(onLocationChangedSpy.mock.calls).toHaveLength(2)
})

it('only renders one time when mounted', () => {
let renderCount = 0

const RenderCounter = () => {
renderCount++
return null
}

mount(
<Provider store={store}>
<ConnectedRouter {...props}>
<Route path="/" component={RenderCounter} />
</ConnectedRouter>
</Provider>
)

expect(renderCount).toBe(1)
})

it('does not render again when non-related action is fired', () => {
// Initialize the render counter variable
let renderCount = 0

// Create redux store with router state
store = createStore(
combineReducers({
incrementReducer: (state = 0, action = {}) => {
if (action.type === 'testAction')
return ++state

return state
},
router: connectRouter(history)
}),
compose(applyMiddleware(routerMiddleware(history)))
)


const RenderCounter = () => {
renderCount++
return null
}

mount(
<Provider store={store}>
<ConnectedRouter {...props}>
<Route path="/" component={RenderCounter} />
</ConnectedRouter>
</Provider>
)

store.dispatch({ type: 'testAction' })
history.push('/new-location')
expect(renderCount).toBe(2)
})
})

describe('Redux DevTools', () => {
Expand Down

0 comments on commit c5eebfc

Please sign in to comment.