@@ -153,63 +153,6 @@ class FeatureTests: XCTestCase {
153
153
}
154
154
```
155
155
156
-
157
- <!--
158
- ## Altered execution contexts
159
-
160
- It is possible to completely alter the execution context in which a feature's logic runs, which is
161
- great for tests. It means your feature doesn't need to actually make network requests just to test
162
- how your feature deals with data returned from an API, and your feature doesn't need to interact
163
- with the file system just to test how data gets loaded or persisted.
164
-
165
- The tool for doing this is ``withDependencies(_:operation:)``, which allows you to specify
166
- which dependencies should be overridden for the test, and then construct your feature's model in
167
- that context:
168
-
169
- ```swift
170
- @Test
171
- func feature() async {
172
- let model = withDependencies {
173
- $0.continuousClock = .immediate
174
- $0.date.now = Date(timeIntervalSince1970: 1234567890)
175
- } operation: {
176
- FeatureModel()
177
- }
178
-
179
- // Call methods on `model` and make assertions
180
- }
181
- ```
182
-
183
- As long as all of your dependencies are declared with `@Dependency` as instance properties on
184
- `FeatureModel`, its entire execution will happen in a context in which any reference to
185
- `continuousClock` is an `ImmediateClock` and any reference to `date.now` will always report that
186
- the date is "Feb 13, 2009 at 3:31 PM".
187
-
188
- > Note: If you are using XCTest it is important to note that if `FeatureModel` creates _other_
189
- > models inside its methods, then it has to be careful about how it does so. In order for
190
- > `FeatureModel`'s dependencies to propagate to the new child model, it must construct the child
191
- > model in an altered execution context that passes along the dependencies. The tool for this is
192
- > ``withDependencies(from:operation:fileID:filePath:line:column:)`` and can be used simply like
193
- > this:
194
- >
195
- > ```swift
196
- > @Observable
197
- > class FeatureModel {
198
- > // ...
199
- >
200
- > func buttonTapped() {
201
- > self.child = withDependencies(from: self) {
202
- > ChildModel()
203
- > }
204
- > }
205
- > }
206
- > ```
207
- >
208
- > This guarantees that when `FeatureModel`'s dependencies are overridden in tests that it will also
209
- > trickle down to `ChildModel`.
210
-
211
- -->
212
-
213
156
## Changing dependencies during tests
214
157
215
158
While it is most common to set up all dependencies at the beginning of a test and then make
0 commit comments