How to mock grpc model in Swift

Issue #306

1
2
3
4
5
6
7
8
9
let json: [String: Any] = [
"id": "123",
"name": "Thor",
"isInMarvel": true
]

let data = try JSONSerialization.data(withJSONObject: json, options: [])
let string = String(data: data, encoding: .utf8)!
return try Hero(jsonString: string)

If we use withValue from How to simplify struct mutating in Swift then we can mock easily

1
2
3
4
5
6
7
8
9
extension Hero {
static func mock() -> Hero {
return withValue(Hero()) {
$0.id = "123"
$0.name = "Thor"
$0.isInMarvel = true
}
}
}

Comments