diff --git a/Tests/ComposableArchitectureTests/ObservableTests.swift b/Tests/ComposableArchitectureTests/ObservableTests.swift index d6ddab35337c..5e617a46d6bc 100644 --- a/Tests/ComposableArchitectureTests/ObservableTests.swift +++ b/Tests/ComposableArchitectureTests/ObservableTests.swift @@ -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.")