Skip to content

Commit 47e5692

Browse files
Added failing test to document behavior with observation/identified array (#3346)
* Added failing test to document behavior with observation and identified array. * Update Tests/ComposableArchitectureTests/ObservableTests.swift --------- Co-authored-by: Stephen Celis <[email protected]>
1 parent 3425878 commit 47e5692

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Tests/ComposableArchitectureTests/ObservableTests.swift

+24
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,30 @@ final class ObservableTests: BaseTCATestCase {
1818
XCTAssertEqual(state.count, 1)
1919
}
2020

21+
func testCopyMutation() async {
22+
XCTTODO("""
23+
Ideally this test would pass but it does not because making a copy of a child state, mutating
24+
it, and assigning it does not change the identified array's IDs, and therefore the fast-path
25+
of _$isIdentityEqual prevents observation.
26+
""")
27+
28+
var state = ParentState(children: [ChildState(count: 42)])
29+
let countDidChange = self.expectation(description: "count.didChange")
30+
var copy = state.children[0]
31+
copy.count += 1
32+
33+
withPerceptionTracking {
34+
_ = state.children[0].count
35+
} onChange: {
36+
countDidChange.fulfill()
37+
}
38+
39+
state.children[0] = copy
40+
41+
await self.fulfillment(of: [countDidChange], timeout: 0.1)
42+
XCTAssertEqual(state.children[0].count, 43)
43+
}
44+
2145
func testReplace() async {
2246
XCTTODO("Ideally this would pass but we cannot detect this kind of mutation currently.")
2347

0 commit comments

Comments
 (0)