Created
December 17, 2018 12:30
-
-
Save graphicbeacon/9fb12aabb2fe4fe7caa15ca3966a5371 to your computer and use it in GitHub Desktop.
Code snipper for "Write your first Web Scraper in Dart" Medium post
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
| 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