Skip to content

Commit

Permalink
Added failing test to document behavior with observation/identified a…
Browse files Browse the repository at this point in the history
…rray (#3346)

* Added failing test to document behavior with observation and identified array.

* Update Tests/ComposableArchitectureTests/ObservableTests.swift

---------

Co-authored-by: Stephen Celis <stephen@stephencelis.com>
  • Loading branch information
mbrandonw and stephencelis committed Sep 4, 2024
1 parent 3425878 commit 47e5692
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 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

0 comments on commit 47e5692

Please sign in to comment.