test: add integration test
This commit is contained in:
committed by
Benedikt Rötsch
parent
703a5e4d3a
commit
d7654bb9bf
2
app.js
2
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
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
31
test/integration/courses.test.js
Normal file
31
test/integration/courses.test.js
Normal file
@@ -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(/<h1>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()
|
||||
})
|
||||
})
|
||||
})
|
||||
9
test/integration/index.test.js
Normal file
9
test/integration/index.test.js
Normal file
@@ -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)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user