Using a nodejs, javascript and express stack I am testing out examples from the book "Web Development with Node and Express: Leveraging the Javascript Stack". I am currently running an example to preform Page Testing using mocha and chai. github link
Can someone explain where I will see the result of a test passing or failing? It could be possible the env is not set to development, and that could be anther reason for me not seeing changes during the test. I am not certain what I should be observing. For example, should there be output in the browser or the console? Below is the partial code I am implementing:
meadowlark.js
app.use( function( req, res, next){
res.locals.showTests = app.get(' env') !== 'production' &&
req.query.test = = = '1'; next(); });
app.get('/ about', function( req, res) {
res.render(' about', {
fortune: fortune.getFortune(),
pageTestScript: '/qa/tests-about.js' } ); });
// routes go here....
In the head:
<head>
<title> Meadowlark Travel </ title >
{{# if showTests}}
<link rel ="stylesheet" href ="/vendor/ mocha.css">
{{/ if}}
<script src ="// code.jquery.com/ jquery-2.0.2. min.js" > </ script >
</head >
In the body ......
{{# if showTests}}
< div id =" mocha" > </ div >
< script src ="/ vendor/ mocha.js" > </ script >
< script src ="/ vendor/ chai.js" > </ script >
< script >
mocha.ui(' tdd');
var assert = chai.assert;
</ script >
< script src ="/ qa/ tests-global.js" > </ script >
{{# if pageTestScript}}
< script src ="{{ pageTestScript}}" > </ script >
{{/ if}}
< script > mocha.run(); </ script >
{{/ if}}
</ body >
qa/tests-global.js
suite(' Global Tests', function(){
test(' page has a valid title', function(){
assert(document.title && document.title.match(/\ S/) &&
document.title.toUpperCase() != = 'TODO'); }); });
qa/tests-about.js
suite('" About" Page Tests', function(){
test(' page should contain link to contact page', function(){
assert( $(' a[ href ="/ contact"]'). length); }); });
To test this the instruction tell me the following: "Now, add test = 1 to the querystring (http:// localhost: 3000/? test = 1), and you’ll see the tests run on the page." I don't see any difference with ?test=1 added to the query string. Any help would be appreciated.
Update: Following the same app.use order as the author did within the meadowlark.js server I was able to successfully get the test displayed in the browser.