Skip to content

Instantly share code, notes, and snippets.

@hjJunior
Last active April 12, 2019 19:44
Show Gist options
  • Save hjJunior/01fcafcfee87fb47b0ee6892ead763a5 to your computer and use it in GitHub Desktop.
Save hjJunior/01fcafcfee87fb47b0ee6892ead763a5 to your computer and use it in GitHub Desktop.
class MyIp {
MyIp(this._client);
final Client _client;
Future<String> get ipAddress async {
final apiResult = await _client.get('https://api.ipify.org/?format=json');
return json.decode(apiResult.body)['ip'];
}
}
// Testing code
test('it get my ip', () async {
final fakeClient = MockClient((_) async =>
Response(json.encode({"ip": "192.168.0.1"}), 200)
);
final myIp = MyIp(fakeClient);
expect(await myIp.ipAddress, "192.168.0.1");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment