no ability to reset store
Closed this issue · 1 comments
mbardauskas commented
running tests with jest and doing jest.resetModules()
before each test results in warning:
[mobx] Warning: there are multiple mobx instances active. This might lead to unexpected results. See https://github.com/mobxjs/mobx/issues/1082 for details.
example code
describe('store:', () => {
let uut
beforeEach(() => {
jest.resetModules()
uut = require('./store').default
})
it('should get event filters', () => {
expect(uut.getFilters()).toEqual([])
})
it('should get events', () => {
expect(uut.getEvents()).toEqual([])
})
})
can we have an ability to reset store? or what are our options
DanielZlotin commented
The only thing I could come up with to solve this usecase is to deepClone the initialState passed to remx.state(initialState)
, which incurs runtime costs.
I didn't push this change, as I'm not sure it's a good idea.
The other option is to wrap all your store logic in an object and create a new one each time (for example create it in your module/app's entry point and hold it for the duration of the app (like you would do with redux). For example.