Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save zombiemachines/f3918c6f50f8c6403265b6a909e9ed3d to your computer and use it in GitHub Desktop.

Select an option

Save zombiemachines/f3918c6f50f8c6403265b6a909e9ed3d to your computer and use it in GitHub Desktop.
Code snipper for "Write your first Web Scraper in Dart" Medium post
void main() {
MockClient client = null;
test('calling initiate(client) returns a list of storylinks', () async {
// Arrange
client = MockClient((req) => Future(() => Response('''
<body>
<table><tbody><tr>
<td class="title">
<a class="storylink" href="https://dartlang.org">Get started with Dart</a>
</td>
</tr></tbody></table>
</body>
''', 200)));
// Act
var response = await hacker_news_scraper.initiate(client);
// Assert
expect(
response,
equals(json.encode([
{
'title': 'Get started with Dart',
'href': 'https://dartlang.org',
}
])));
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment