Last active
April 12, 2019 19:44
-
-
Save hjJunior/01fcafcfee87fb47b0ee6892ead763a5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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