-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b1dce3e
commit 105a161
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ | ||
/* WWW app integration/acceptance tests (just a few sample tests, not full coverage) */ | ||
/* */ | ||
/* These tests require www.localhost to be set in /etc/hosts. */ | ||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ | ||
|
||
import supertest from 'supertest'; // SuperAgent driven library for testing HTTP servers | ||
import { expect } from 'chai'; // BDD/TDD assertion library | ||
import { JSDOM as JsDom } from 'jsdom'; // JavaScript implementation of DOM and HTML standards | ||
|
||
import app from '../../app.js'; | ||
|
||
const appAdmin = supertest.agent(app.listen()).host('www.localhost'); | ||
|
||
|
||
describe(`WWW app (${app.env})`, function() { | ||
describe('basic tests', function() { | ||
it('sees home page', async function() { | ||
const response = await appAdmin.get('/'); | ||
expect(response.status).to.equal(200); | ||
const document = new JsDom(response.text).window.document; | ||
expect(document.querySelector('h1').textContent).to.equal('Koa Sample App (handlebars templating + RESTful API using MySQL, on Node.js)'); | ||
}); | ||
|
||
it('sees contact page', async function() { | ||
const response = await appAdmin.get('/contact'); | ||
expect(response.status).to.equal(200); | ||
const document = new JsDom(response.text).window.document; | ||
expect(document.querySelector('h1').textContent).to.equal('Koa Sample App contact page'); | ||
}); | ||
|
||
it('submits contact page', async function() { | ||
const response = await appAdmin.post('/contact').send({ email: 'user@example.com', message: 'Hi there' }); | ||
expect(response.status).to.equal(302); | ||
expect(response.headers.location).to.equal('/contact'); | ||
}); | ||
}); | ||
}); |