Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ final class ExampleMapTests: XCTestCase {
observer.objectWillChange.send()
}

await context.waitUntilNextUpdate()
await context.waitForUpdate()

XCTAssertEqual(context.watch(atom), .authorizedAlways)

observer.objectWillChange.send()
let didUpdate = await context.waitUntilNextUpdate(timeout: 1)
let didUpdate = await context.waitForUpdate(timeout: 1)

// Should not update if authorizationStatus is not changed.
XCTAssertFalse(didUpdate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ final class ExampleVoiceMemoTests: XCTestCase {

XCTAssertEqual(context.watch(atom), .suspending)

await context.waitUntilNextUpdate()
await context.waitForUpdate()

XCTAssertEqual(context.watch(atom), .success(.zero))

Expand All @@ -74,7 +74,7 @@ final class ExampleVoiceMemoTests: XCTestCase {

XCTAssertEqual(context.watch(atom), .suspending)

await context.waitUntilNextUpdate()
await context.waitForUpdate()

XCTAssertEqual(context.watch(atom), .success(10))
}
Expand Down Expand Up @@ -178,7 +178,7 @@ final class ExampleVoiceMemoTests: XCTestCase {

XCTAssertEqual(context.watch(atom), .suspending)

await context.waitUntilNextUpdate()
await context.waitForUpdate()

XCTAssertEqual(context.watch(atom), .success(.zero))

Expand All @@ -187,7 +187,7 @@ final class ExampleVoiceMemoTests: XCTestCase {

XCTAssertEqual(context.watch(atom), .suspending)

await context.waitUntilNextUpdate()
await context.waitForUpdate()

XCTAssertEqual(context.watch(atom), .success(10))
}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,7 @@ A context that can simulate any scenarios in which atoms are used from a view or
|:--|:--|
|[unwatch(_:)](https://ra1028.github.io/swiftui-atom-properties/documentation/atoms/atomtestcontext/unwatch(_:))|Simulates a scenario in which the atom is no longer watched.|
|[override(_:with:)](https://ra1028.github.io/swiftui-atom-properties/documentation/atoms/atomtestcontext/override(_:with:)-1ce4h)|Overwrites the output of a specific atom or all atoms of the given type with the fixed value.|
|[waitUntilNextUpdate(timeout:)](https://ra1028.github.io/swiftui-atom-properties/documentation/atoms/atomtestcontext/waituntilnextupdate(timeout:))|Waits until any of atoms watched through this context is updated.|
|[waitForUpdate(timeout:)](https://ra1028.github.io/swiftui-atom-properties/documentation/atoms/atomtestcontext/waitforupdate(timeout:))|Waits until any of atoms watched through this context is updated.|
|[onUpdate](https://ra1028.github.io/swiftui-atom-properties/documentation/atoms/atomtestcontext/onupdate)|Sets a closure that notifies there has been an update to one of the atoms.|

---
Expand Down
4 changes: 2 additions & 2 deletions Sources/Atoms/Context/AtomTestContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public struct AtomTestContext: AtomWatchableContext {
/// let initialPhase = context.watch(AsyncCalculationAtom().phase)
/// XCTAssertEqual(initialPhase, .suspending)
///
/// let didUpdate = await context.waitUntilNextUpdate()
/// let didUpdate = await context.waitForUpdate()
/// let currentPhase = context.watch(AsyncCalculationAtom().phase)
///
/// XCTAssertTure(didUpdate)
Expand All @@ -45,7 +45,7 @@ public struct AtomTestContext: AtomWatchableContext {
/// the next update. The default timeout interval is `60`.
/// - Returns: A boolean value indicating whether an update is done.
@discardableResult
public func waitUntilNextUpdate(timeout interval: TimeInterval = 60) async -> Bool {
public func waitForUpdate(timeout interval: TimeInterval = 60) async -> Bool {
let updates = AsyncStream<Void> { continuation in
let cancellable = state.notifier.sink(
receiveCompletion: { completion in
Expand Down
16 changes: 8 additions & 8 deletions Tests/AtomsTests/Atom/AsyncSequenceAtomTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@ final class AsyncSequenceAtomTests: XCTestCase {
do {
// Value
pipe.continuation.yield(0)
await context.waitUntilNextUpdate()
await context.waitForUpdate()

XCTAssertEqual(context.watch(atom).value, 0)
}

do {
// Failure
pipe.continuation.finish(throwing: URLError(.badURL))
await context.waitUntilNextUpdate()
await context.waitForUpdate()

XCTAssertEqual(context.watch(atom).error as? URLError, URLError(.badURL))
}

do {
// Yield value after finish
pipe.continuation.yield(1)
let didUpdate = await context.waitUntilNextUpdate(timeout: 1)
let didUpdate = await context.waitForUpdate(timeout: 1)

XCTAssertFalse(didUpdate)
}
Expand All @@ -43,7 +43,7 @@ final class AsyncSequenceAtomTests: XCTestCase {
context.unwatch(atom)

pipe.continuation.yield(0)
let didUpdate = await context.waitUntilNextUpdate(timeout: 1)
let didUpdate = await context.waitForUpdate(timeout: 1)

XCTAssertFalse(didUpdate)
}
Expand All @@ -54,7 +54,7 @@ final class AsyncSequenceAtomTests: XCTestCase {
context.unwatch(atom)

pipe.continuation.finish(throwing: URLError(.badURL))
let didUpdate = await context.waitUntilNextUpdate(timeout: 1)
let didUpdate = await context.waitForUpdate(timeout: 1)

XCTAssertFalse(didUpdate)
}
Expand Down Expand Up @@ -144,13 +144,13 @@ final class AsyncSequenceAtomTests: XCTestCase {
XCTAssertTrue(updatedValues.isEmpty)

pipe.continuation.yield(0)
await context.waitUntilNextUpdate()
await context.waitForUpdate()

pipe.continuation.yield(1)
await context.waitUntilNextUpdate()
await context.waitForUpdate()

pipe.continuation.yield(2)
await context.waitUntilNextUpdate()
await context.waitForUpdate()

XCTAssertEqual(
updatedValues,
Expand Down
2 changes: 1 addition & 1 deletion Tests/AtomsTests/Atom/ModifiedAtomTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ final class ModifiedAtomTests: XCTestCase {
context[base] = "testtest"
}

await context.waitUntilNextUpdate()
await context.waitForUpdate()
XCTAssertEqual(context.watch(atom), 8)
}

Expand Down
10 changes: 5 additions & 5 deletions Tests/AtomsTests/Atom/ObservableObjectAtomTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ final class ObservableObjectAtomTests: XCTestCase {
}

object.update()
await context.waitUntilNextUpdate()
await context.waitForUpdate()

XCTAssertEqual(snapshot, 1)
}
Expand All @@ -68,7 +68,7 @@ final class ObservableObjectAtomTests: XCTestCase {
}

object.update()
await context.waitUntilNextUpdate()
await context.waitForUpdate()

XCTAssertEqual(updateCount, 1)
}
Expand All @@ -86,7 +86,7 @@ final class ObservableObjectAtomTests: XCTestCase {
updateCount = object.updatedCount
}
object.update()
await context.waitUntilNextUpdate()
await context.waitForUpdate()

XCTAssertTrue(object === overrideObject)
XCTAssertEqual(updateCount, 1)
Expand All @@ -105,7 +105,7 @@ final class ObservableObjectAtomTests: XCTestCase {
updateCount = object.updatedCount
}
object.update()
await context.waitUntilNextUpdate()
await context.waitForUpdate()

XCTAssertTrue(object === overrideObject)
XCTAssertEqual(updateCount, 1)
Expand All @@ -123,7 +123,7 @@ final class ObservableObjectAtomTests: XCTestCase {
XCTAssertTrue(updatedObjects.isEmpty)
object.update()

await context.waitUntilNextUpdate()
await context.waitForUpdate()

XCTAssertEqual(updatedObjects.last?.updatedCount, 1)
}
Expand Down
16 changes: 8 additions & 8 deletions Tests/AtomsTests/Atom/PublisherAtomTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,23 @@ final class PublisherAtomTests: XCTestCase {
// Value
subject.send(0)

await context.waitUntilNextUpdate()
await context.waitForUpdate()
XCTAssertEqual(context.watch(atom), .success(0))
}

do {
// Error
subject.send(completion: .failure(URLError(.badURL)))

await context.waitUntilNextUpdate()
await context.waitForUpdate()
XCTAssertEqual(context.watch(atom), .failure(URLError(.badURL)))
}

do {
// Send value after completion
subject.send(1)

let didUpdate = await context.waitUntilNextUpdate(timeout: 1)
let didUpdate = await context.waitForUpdate(timeout: 1)
XCTAssertFalse(didUpdate)
}

Expand All @@ -45,7 +45,7 @@ final class PublisherAtomTests: XCTestCase {
context.unwatch(atom)
subject.send(0)

let didUpdate = await context.waitUntilNextUpdate(timeout: 1)
let didUpdate = await context.waitForUpdate(timeout: 1)
XCTAssertFalse(didUpdate)
}

Expand All @@ -54,7 +54,7 @@ final class PublisherAtomTests: XCTestCase {
context.unwatch(atom)
subject.send(completion: .failure(URLError(.badURL)))

let didUpdate = await context.waitUntilNextUpdate(timeout: 1)
let didUpdate = await context.waitForUpdate(timeout: 1)
XCTAssertFalse(didUpdate)
}

Expand Down Expand Up @@ -143,13 +143,13 @@ final class PublisherAtomTests: XCTestCase {
XCTAssertTrue(updatedValues.isEmpty)

subject.send(0)
await context.waitUntilNextUpdate()
await context.waitForUpdate()

subject.send(1)
await context.waitUntilNextUpdate()
await context.waitForUpdate()

subject.send(2)
await context.waitUntilNextUpdate()
await context.waitForUpdate()

XCTAssertEqual(
updatedValues,
Expand Down
2 changes: 1 addition & 1 deletion Tests/AtomsTests/Atom/StateAtomTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ final class StateAtomTests: XCTestCase {
context[Dependency1Atom()] = 0
}

await context.waitUntilNextUpdate()
await context.waitForUpdate()

let value2 = context.watch(TestAtom())
XCTAssertEqual(value2, 0)
Expand Down
6 changes: 3 additions & 3 deletions Tests/AtomsTests/Context/AtomTestContextTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ final class AtomTestContextTests: XCTestCase {
XCTAssertTrue(isCalled)
}

func testWaitUntilNextUpdate() async {
func testWaitForUpdate() async {
let atom = TestStateAtom(defaultValue: 0)
let context = AtomTestContext()

Expand All @@ -41,11 +41,11 @@ final class AtomTestContextTests: XCTestCase {
context[atom] = 1
}

let didUpdate0 = await context.waitUntilNextUpdate()
let didUpdate0 = await context.waitForUpdate()

XCTAssertTrue(didUpdate0)

let didUpdate1 = await context.waitUntilNextUpdate(timeout: 1)
let didUpdate1 = await context.waitForUpdate(timeout: 1)

XCTAssertFalse(didUpdate1)
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/AtomsTests/Modifier/TaskPhaseModifierTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ final class TaskPhaseModifierTests: XCTestCase {

XCTAssertEqual(context.watch(atom.phase), .suspending)

await context.waitUntilNextUpdate(timeout: 1)
await context.waitForUpdate(timeout: 1)

XCTAssertEqual(context.watch(atom.phase), .success(0))
}
Expand Down