Skip to content

Instantly share code, notes, and snippets.

@HasanGokce
Created December 17, 2020 13:35
Show Gist options
  • Save HasanGokce/a1aaf6aa1cf1a91466ed7cff9b7d612a to your computer and use it in GitHub Desktop.
Save HasanGokce/a1aaf6aa1cf1a91466ed7cff9b7d612a to your computer and use it in GitHub Desktop.
Response Content
const {assert} = require('chai');
const request = require('supertest');
const {jsdom} = require('jsdom');
const app = require('../../app');
const parseTextFromHTML = (htmlAsString, selector) => {
const selectedElement = jsdom(htmlAsString).querySelector(selector);
if (selectedElement !== null) {
return selectedElement.textContent;
} else {
throw new Error(`No element with selector ${selector} found in HTML string`);
}
};
describe('root page', () => {
describe('GET request', () => {
it('returns a 200 status', async () => {
const response = await request(app).
get('/');
assert.equal(response.status, 200);
});
it('contains the correct title', async () => {
const response = await request(app).
get('/');
assert.equal(parseTextFromHTML(response.text, '#page-title'), 'Messaging App')
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment