From d7654bb9bf0ba3cb37841b89a985614348f37fce Mon Sep 17 00:00:00 2001 From: Khaled Garbaya Date: Wed, 18 Oct 2017 15:29:18 +0200 Subject: [PATCH] test: add integration test --- app.js | 2 +- package.json | 9 +++++++-- test/integration/courses.test.js | 31 +++++++++++++++++++++++++++++++ test/integration/index.test.js | 9 +++++++++ 4 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 test/integration/courses.test.js create mode 100644 test/integration/index.test.js diff --git a/app.js b/app.js index e81720b..be11e27 100644 --- a/app.js +++ b/app.js @@ -34,7 +34,7 @@ app.use(breadcrumb()) // Pass our application state and custom helpers to all our templates app.use(async function (req, res, next) { - // Inject ucstom helpers + // Inject custom helpers res.locals.helpers = helpers // Express query string diff --git a/package.json b/package.json index ac8e61c..7247f0a 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,9 @@ "start:watch": "nodemon ./bin/www --ignore public/", "start": "node ./bin/www", "lint": "eslint ./app.js routes", - "format": "eslint --fix . bin --ignore public node_modules" + "format": "eslint --fix . bin --ignore public node_modules", + "test:integration": "jest test/integration", + "test:integration:watch": "jest test/integration --watch" }, "engines": { "node": ">=8.4.0" @@ -30,7 +32,10 @@ "eslint-config-standard": "^6.2.1", "eslint-plugin-promise": "^3.4.2", "eslint-plugin-standard": "^2.0.1", + "jest": "^21.2.1", "nodemon": "^1.12.1", - "pug-lint": "^2.5.0" + "pug-lint": "^2.5.0", + "superagent": "^3.6.3", + "supertest": "^3.0.0" } } diff --git a/test/integration/courses.test.js b/test/integration/courses.test.js new file mode 100644 index 0000000..ba61e42 --- /dev/null +++ b/test/integration/courses.test.js @@ -0,0 +1,31 @@ +/* global describe, test, expect */ +const app = require('../../app') +const request = require('supertest') + +describe('courses', () => { + test('it should render a list of courses', () => { + return request(app).get('/courses') + .expect(200) + .then((response) => { + expect(response.text.match(/

All Courses /)).toBeTruthy() + }) + }) + test('it should render a course', () => { + return request(app).get('/courses/headless-content-management-using-contentful') + .expect(200) + .then((response) => { + expect(response.text.match(/class="course__title"/)).toBeTruthy() + }) + }) + test('it should return 404 when a course does not exist', () => { + return request(app).get('/courses/dont-exist').expect(404) + }) + + test('it should render a lesson', () => { + return request(app).get('/courses/headless-content-management-using-contentful/lessons/content-from-your-idea-to-any-display') + .expect(200) + .then((response) => { + expect(response.text.match(/class="lesson__title"/)).toBeTruthy() + }) + }) +}) diff --git a/test/integration/index.test.js b/test/integration/index.test.js new file mode 100644 index 0000000..77105c6 --- /dev/null +++ b/test/integration/index.test.js @@ -0,0 +1,9 @@ +/* global describe, test */ +const app = require('../../app') +const request = require('supertest') + +describe('Home page', () => { + test('it should render the landing page', () => { + return request(app).get('/').expect(200) + }) +})