Skip to content

Instantly share code, notes, and snippets.

@graphicbeacon
Created December 17, 2018 12:30
Show Gist options
  • Select an option

  • Save graphicbeacon/9fb12aabb2fe4fe7caa15ca3966a5371 to your computer and use it in GitHub Desktop.

Select an option

Save graphicbeacon/9fb12aabb2fe4fe7caa15ca3966a5371 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