I already am implementing unit tests using redux-mock-store
.
I would like to perform an integration test suite on a react-native app that uses store singletons just fine. However even though console.log
s reach so far as the reducer function (and seems to be working correctly) state on the store does not change.
// __tests__/things.js
jest.mock('../app/store')
import 'react-native'
import * as selectors from '../app/selectors'
import * as sagas from '../app/sagas'
import { store } from '../app/store'
describe('Things', () => {
it('should toggle', async () => {
const previousCounter = selectors.count()
await sagas.increment()
expect(store.getState().count).toEqual(previousCounter)
})
})
Meanwhile the mock store implementation:
// __mocks__
import { createStore } from 'redux'
import rootReducer from '../reducers'
export const store = createStore(rootReducer, {})
EDIT: A sample reducer
// app/reducers.js
function rootReducer (state = { count: 0 }, action = {}) {
const count = state.count + 1
return { ...state, count }
}
Everything works great, but the state does not change. If I implement an observer by subscribing to the store, I see the action series being dispatched.