Moya stub request in BDD tests

I want to make Moya a stub request in Quick / Nimble BDD. Moya has a parameter sampleDatathat I created using the JSON file:

var sampleData: Data {
    switch self {
    case .getPlaces:
        // Provided that project have a file named get_places.json in it bundle.
        guard let path = Bundle.main.path(forResource: "get_places", ofType: "json"),
            let data = Data(base64Encoded: path) else {
                return Data()
        }
        return data
    case .getPlaceDetail:
        // Provided that project have a file named get_place_detail.json in it bundle.
        guard let path = Bundle.main.path(forResource: "get_place_detail", ofType: "json"),
            let data = Data(base64Encoded: path) else {
                return Data()
        }
        return data
    }
}

How can I use this parameter in tests? Any ideas to query Moya in tests?

Thanks!

+6
source share
1 answer

Just use your provider, as in your real code. Moya discovers that the current target is a test target and will return sample data instead of executing a query

+10
source

Source: https://habr.com/ru/post/1014635/


All Articles