Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shared state shows test change in the wrong action #3455

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

rcarver
Copy link
Contributor

@rcarver rcarver commented Oct 20, 2024

When modifying a @Shared value in a delegate action, the TestStore shows the state change in the original action, not the delegate.

This PR is a failing test only. In reality this would be a parent feature responding to the delegate, but the test works within a single reducer.

@mbrandonw
Copy link
Member

Hi @rcarver, this is a known, but also expected, issue with shared state and the test store. The fix is to have the test store not eagerly process actions from effects, but unfortunately that would be a breaking change. And so we will have to wait until 2.0 to fix that.

For now you will just need to assert on shared state in the received, or you can also do it after the send:

await store.send(.incrementSharedInDelegate)
store.state.$stats.assert {
  $0.count = 1
}
await store.receive(\.delegate.didIncrement) {
  $0.count = 1
}

We would be happy to accept this PR if you want to mark this test as an expected failure. You can search the repo for XCTTODO to see how we have done this in a few spots in the code base. That will help us keep track of this when we finally fix the problem.

@rcarver
Copy link
Contributor Author

rcarver commented Oct 21, 2024

Thanks @mbrandonw. I added XCTTODO to the existing test, and also added a new test showing the behavior today.

FYI the version you proposed doesn't pass for me

await store.send(.incrementSharedInDelegate)
store.state.$stats.assert {
  $0.count = 1
}
await store.receive(\.delegate.didIncrement) {
  $0.count = 1
}

But this form does

    await store.send(.incrementSharedInDelegate) {
      $0.stats.count = 1
    }
    await store.receive(\.delegate.didIncrement) {
      $0.count = 1
    }

@rcarver rcarver force-pushed the test_diff_shared_value_in_wrong_action branch from f6fe6c6 to 4cfe10d Compare October 21, 2024 21:08
@mbrandonw
Copy link
Member

FYI the version you proposed doesn't pass for me

Oh, huh, do you remember what the error was?

@rcarver
Copy link
Contributor Author

rcarver commented Oct 21, 2024

@mbrandonw oh sorry I meant to add that, here you go:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants