Different tests competing in modifying the store
- Dominant language
- JavaScript
- Stars
- 3.4k
- Forks
- 312
- PR merge metrics
- No merged PRs in 30d
Description
I am trying to write some tests for my store but I found that different tests are competing in modifying the same store instance so my assertions are mostly failing when I run them together while each of them can pass if I run them one by one. How should I resolve this?
Below show an example, while the "SOME_ACTION" would not change the value of `amount`
```
it('test 1', done => {
AltClaimFormStore.state.amount = 12.3;
var action = ClaimFormActions.SOME_ACTION;
alt.dispatcher.dispatch({ action });
AltClaimFormStore.listen(function () {
if (!AltClaimFormStore.state.isUpdating) {
expect(AltClaimFormStore.state.amount).toBe(12.3);
done();
}
});
});
it('test 2', done => {
AltClaimFormStore.state.amount = 12.4;
var action = ClaimFormActions.SOME_ACTION;
alt.dispatcher.dispatch({ action });
AltClaimFormStore.listen(function () {
if (!AltClaimFormStore.state.isUpdating) {
expect(AltClaimFormStore.state.amount).toBe(12.4);
done();
}
});
});
```
Contributor guide
Research direction
Use the two shown test cases involving AltClaimFormStore, ClaimFormActions.SOME_ACTION, and the dispatcher as the reproduction. Start by checking how the shared store and listeners are initialized between tests; done means both tests pass together consistently without competing state changes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100