You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I try to stub closure with will in a static function, it shows error "Unable to infer type of a closure parameter", if I specify the type in the closure parameter, it can be built successfully, but crash when running test.
Example
Source class
class NetworkHelper {
// MARK: - Network requests
static func get(
url: URL,
token: String?,
completion: @escaping (Data?, URLResponse?, Error?) -> Void
) {
var request = URLRequest(url: url)
request.httpMethod = "GET"
// Sample server doesn't need a token as it runs locally
if let token {
request.addValue("Bearer \(token)", forHTTPHeaderField: "Authorization")
}
URLSession.shared.dataTask(with: request, completionHandler: completion).resume()
}
}
Test class
func testRequestOtpSuccess() throws {
let helper = type(of: mock(NetworkHelper.self))
given(helper.get(url: any(), token: any(), completion: any())).will { completion in //This will show error when building
completion(nil, nil, nil)
}
// The following ways will crash the app
// error: memory read failed for 0x0
given(helper.get(url: any(), token: any(), completion: any())).will { (completion: (Data?, URLResponse?, Error?) -> Void) in
completion(nil, nil, nil)
}
given(helper.get(url: any(), token: any(), completion: any())).will {
}
}
Expected Behavior
It should be able to stub and run without crashing
Environment
Mockingbird CLI version (0.20.0)
Xcode and Swift version (swift-driver version: 1.62.15 Apple Swift version 5.7.2 (swiftlang-5.7.2.135.5 clang-1400.0.29.51) Target: arm64-apple-macosx13.0)
Package manager (SPM project)
Unit testing framework (XCTest)
Custom configuration
Mockingbird ignore files
Supporting source files
The text was updated successfully, but these errors were encountered:
New Issue Checklist
Overview
When I try to stub closure with
will
in a static function, it shows error "Unable to infer type of a closure parameter", if I specify the type in the closure parameter, it can be built successfully, but crash when running test.Example
Source class
Test class
Expected Behavior
It should be able to stub and run without crashing
Environment
The text was updated successfully, but these errors were encountered: