Test Cases for Telescope

This week I was working on creating test cases for Telescope. I was assigned to an issue-615. The main point of this issue was to create tests for cases where a client requests different content types of text for a given post ID.  The content types that I covered were JSON, Text, and HTML.

Automated tests for Telescope’s REST API endpoints are written using Jest and Supertest. I started by researching both of them and skimming documentation provided online.

Jest is a JavaScript testing framework that focuses on simplicity. It works with Node, Angular and Vue. It is an open-source project and its repository on GitHub is maintained by Facebook. Jest has a nice and easy to understand documentation. Also, I found Jest cheatsheet which was helpful in writing tests for Telescope.

Supertest is a library made specifically for testing NodeJS HTTP servers. It is also an open-source project with handy documentation on its GitHub page.

My task for this issue was to:

  • Update the two objects (addedPost and receivedPost) so that the HTML property contains real HTML (content

    ) and the text property contains the same content as text stripped of HTML (content),

  • Convert all the it() to test(),
  • Write cases for requesting Text, HTML, and JSON.

When I was writing tests for ‘request test’ and ‘request HTML’ I faced an issue – I was using the response body (res.body) to compare received data with testing data and res.body was always empty. It did not make any sense, so I’ve spent some time researching why it is not working the way I want. I found out that if content type header is text/plain or text/HTML, then the response body won’t be parsed. For cases like this, there is res.text that will contain data as a string. Here is the code snippet of it:

Screen Shot 2020-04-01 at 9.31.38 PM

The rest of my changes for this PR you could find here.

Thank you for your attention!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s