簡體   English   中英

dart callMatcher命名參數

[英]dart callMatcher named arguments

我正在關注https://www.dartlang.org/articles/mocking-with-dart/,但它沒有說明將調用與命名參數匹配。 我發現了2012年或2013年初的一些帖子,說該帖子不受支持。 有人可以說些什么嗎?

我的情況很簡單-如果使用正確的參數調用get方法,我會嘗試模擬並返回一些數據

class Client {    
    Future<Map> get(String endpoint, {Map query: const {}, ContentType contentType:null}) {
        ...
    }
}

稍后在測試中,我創建了一個模擬

class _ClientMock extends Mock implements Client {}

client = new _ClientMock();

var endpoint = "http://host:8080/hotels";
var query = {"param": "value"};

client.when(callsTo("get", endpoint, query)).thenReturn(new Future.value(serverData));

不幸的是,這不起作用,只是不接受第3個參數。 我嘗試了各種匹配器,但是沒有運氣。

有任何想法嗎?

callsTo方法不處理命名參數, CallMatcher.matches方法也不提供與命名參數匹配的方法。

恐怕模擬庫似乎需要重寫以處理命名參數和位置參數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM