Skip to content

Commit 0479c5d

Browse files
committedDec 23, 2020
Documentation
1 parent da28222 commit 0479c5d

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed
 

‎README.md

+2
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ There are various publisher expectations. Each one waits for a specific publishe
160160

161161
:arrow_right: Related expectations: [elements], [prefix(maxLength)].
162162

163+
Unlike other expectations, `availableElements` does not make a test fail on timeout expiration. It just returns the elements published so far.
164+
163165
Example:
164166

165167
```swift

‎Sources/CombineExpectations/PublisherExpectations/AvailableElements.swift

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@ extension PublisherExpectations {
55
/// the recorded publisher to complete.
66
///
77
/// When waiting for this expectation, the publisher error is thrown if
8-
/// the publisher fails before the expectation has expired..
8+
/// the publisher fails before the expectation has expired.
99
///
1010
/// Otherwise, an array of all elements published before the expectation
1111
/// has expired is returned.
1212
///
13+
/// Unlike other expectations, `AvailableElements` does not make a test fail
14+
/// on timeout expiration. It just returns the elements published so far.
15+
///
1316
/// For example:
1417
///
1518
/// // SUCCESS: no timeout, no error

‎Sources/CombineExpectations/Recorder.swift

+14-4
Original file line numberDiff line numberDiff line change
@@ -288,17 +288,27 @@ extension PublisherExpectations {
288288
}
289289

290290
extension Recorder {
291-
/// Returns a publisher expectation which waits for the timeout to expire.
291+
/// Returns a publisher expectation which waits for the timeout to expire,
292+
/// or the recorded publisher to complete.
292293
///
293-
/// When waiting for this expectation, the publisher error is thrown if the
294-
/// publisher fails before expiration.
294+
/// When waiting for this expectation, the publisher error is thrown if
295+
/// the publisher fails before the expectation has expired.
295296
///
296297
/// Otherwise, an array of all elements published before the expectation
297298
/// has expired is returned.
298299
///
300+
/// Unlike other expectations, `availableElements` does not make a test fail
301+
/// on timeout expiration. It just returns the elements published so far.
302+
///
299303
/// For example:
300304
///
301-
/// // TODO
305+
/// // SUCCESS: no timeout, no error
306+
/// func testTimerPublishesIncreasingDates() throws {
307+
/// let publisher = Timer.publish(every: 0.01, on: .main, in: .common).autoconnect()
308+
/// let recorder = publisher.record()
309+
/// let dates = try wait(for: recorder.availableElements, timeout: ...)
310+
/// XCTAssertEqual(dates.sorted(), dates)
311+
/// }
302312
public var availableElements: PublisherExpectations.AvailableElements<Input, Failure> {
303313
PublisherExpectations.AvailableElements(recorder: self)
304314
}

0 commit comments

Comments
 (0)
Please sign in to comment.