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

Added failing test to document behavior with observation/identified array #3346

Merged
merged 2 commits into from
Sep 4, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Tests/ComposableArchitectureTests/ObservableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,30 @@ final class ObservableTests: BaseTCATestCase {
XCTAssertEqual(state.count, 1)
}

func testCopyMutation() async {
XCTTODO("""
Ideally this test would pass but it does not because making a copy of a child state, mutating
it, and assigning it does not change the identified array's IDs, and therefore the fast-path
of _$isIdentityEqual prevents observation.
""")

var state = ParentState(children: [ChildState(count: 42)])
let countDidChange = self.expectation(description: "count.didChange")
var copy = state.children[0]
copy.count += 1

withPerceptionTracking {
_ = state.children[0].count
} onChange: {
countDidChange.fulfill()
}

state.children[0] = copy

await self.fulfillment(of: [countDidChange], timeout: 0.1)
XCTAssertEqual(state.children[0].count, 43)
}

func testReplace() async {
XCTTODO("Ideally this would pass but we cannot detect this kind of mutation currently.")

Expand Down Expand Up @@ -616,6 +640,7 @@ private struct ChildState: Equatable, Identifiable {
self
}
}
import ComposableArchitectureMacros
stephencelis marked this conversation as resolved.
Show resolved Hide resolved
@ObservableState
private struct ParentState: Equatable {
var child = ChildState()
Expand Down
Loading