From d1eaa5d6aa4704910d85fcbe7a3387dbc61abe80 Mon Sep 17 00:00:00 2001 From: Luke Redpath Date: Tue, 16 Jan 2024 22:03:42 +0000 Subject: [PATCH] Add stack action path element subscript to testing notes (#2704) * Add stack action path element subscript to testing notes Updates the stack navigation documentation to include information on how to test that a specific element action is received using case key paths. Wording could maybe be improved but its a starting point. * Update StackBasedNavigation.md --------- Co-authored-by: Brandon Williams <135203+mbrandonw@users.noreply.github.com> --- .../Articles/StackBasedNavigation.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Sources/ComposableArchitecture/Documentation.docc/Articles/StackBasedNavigation.md b/Sources/ComposableArchitecture/Documentation.docc/Articles/StackBasedNavigation.md index 8732b6ced691..fe3b4a8e3f93 100644 --- a/Sources/ComposableArchitecture/Documentation.docc/Articles/StackBasedNavigation.md +++ b/Sources/ComposableArchitecture/Documentation.docc/Articles/StackBasedNavigation.md @@ -487,6 +487,18 @@ await store.receive(\.path.popFrom) { } ``` +If you need to assert that a specific child action is received, you can construct a case key path +for a specific child element action by subscripting on the `\.path` case with the element ID. + +For example, if the child feature performed an effect that sent an `.response` action, you +can test that it is received: + +```swift +await store.receive(\.path[id: 0].counter.response) { + // ... +} +``` + This shows how we can write very nuanced tests on how parent and child features interact with each other in a navigation stack.