in ApolloTests/FetchQueryTestsSimple.swift [78:101]
func testReturnCacheDataAndFetchCacheHit() throws {
let query = HeroNameQuery()
withCache(initialRecords: InitialCacheRecords.cacheHit) { cache in
let store = ApolloStore(cache: cache)
let client = ApolloClient(networkTransport: mockNetworkTransport, store: store)
let cacheResultExpectation = self.expectation(description: "Query result from cache")
let serverResultExpectation = self.expectation(description: "Query result from server")
client.fetch(query: query, cachePolicy: .returnCacheDataAndFetch) { (result, error) in
if result?.data?.hero?.name == "R2-D2" {
cacheResultExpectation.fulfill()
} else if result?.data?.hero?.name == "Luke Skywalker" {
serverResultExpectation.fulfill()
} else {
XCTFail("Unexpected or nil result: \(String(describing: result))")
}
}
self.waitForExpectations(timeout: 5, handler: nil)
}
}