AsyncMonitor/Tests/AsyncMonitorTests/AsyncCancellableTests.swift
Sami Samhuri d2b4e0e382
Change the KVO monitoring API
Instead of having a values method that observes and monitors, break out
a values method that returns an AsyncStream and then a monitorValues
method that calls values(for: keyPath).monitor. That method is kind of
superfluous, not sure if it's good to keep it or not.
2025-04-26 17:47:12 -07:00

19 lines
552 B
Swift

@testable import AsyncMonitor
import Testing
@MainActor class AsyncCancellableTests {
var cancellables = Set<AnyAsyncCancellable>()
@Test func storeInsertsIntoSetAndKeepsSubjectAlive() throws {
var subject: TestCancellable? = TestCancellable()
weak var weakSubject: TestCancellable? = subject
try #require(subject).store(in: &cancellables)
#expect(cancellables.count == 1)
subject = nil
#expect(weakSubject != nil)
cancellables.removeAll()
#expect(weakSubject == nil)
}
}