Created
July 19, 2021 18:35
-
-
Save mayoff/97c710d9dc61a8d96ef2924e6176f7a0 to your computer and use it in GitHub Desktop.
for pointfree episode 153
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@testable import SwiftUICaseStudies | |
import XCTest | |
class RefreshableTests: XCTestCase { | |
func testVanilla() async { | |
var k: CheckedContinuation<Void, Never>? = nil | |
let viewModel = PullToRefreshViewModel( | |
fetch: { | |
await withCheckedContinuation { | |
k = $0 | |
} | |
return "\($0) is a good number." | |
} | |
) | |
viewModel.incrementButtonTapped() | |
XCTAssertEqual(viewModel.count, 1) | |
let task = Task { | |
await viewModel.getFact() | |
} | |
while k == nil { | |
await Task.yield() | |
} | |
XCTAssertEqual(viewModel.isLoading, true) | |
k!.resume() | |
await task.value | |
XCTAssertEqual(viewModel.fact, "1 is a good number.") | |
XCTAssertEqual(viewModel.isLoading, false) | |
} | |
func testVanilla_Cancellation() async { | |
var k: CheckedContinuation<Void, Never>? = nil | |
let viewModel = PullToRefreshViewModel( | |
fetch: { | |
await withCheckedContinuation { | |
k = $0 | |
} | |
return "\($0) is a good number." | |
} | |
) | |
viewModel.incrementButtonTapped() | |
XCTAssertEqual(viewModel.count, 1) | |
Task { | |
await viewModel.getFact() | |
} | |
while k == nil { | |
await Task.yield() | |
} | |
XCTAssertEqual(viewModel.isLoading, true) | |
viewModel.cancelButtonTapped() | |
XCTAssertNil(viewModel.fact) | |
XCTAssertEqual(viewModel.isLoading, false) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment