I am working through web development with node and express from O'reilly. Testing with Mocha has just been introduced and I am trying to run 2 tests. First is a global test to verify that there is a page title, second is a page specific test to check for a link to the contact page. Mocha loads when I test the page, but neither test runs, as I get "passes:0 fails:0".
I have this code in my main app file:
app.use(function(req,res,next){
res.locals.showTests = app.get('env') !== 'production' && req.query.test === '1';
next();
});
app.get('/', function(req, res){
res.render('home');
});
app. get('/about', function(req,res){
res.render('about', {fortune: fortune.getFortune(),
pageTestScript: '/qa/tests-about.js'
});
});
This is my tests-about.js
suite('"About" Page Tests', function(){
test('page should contain link to contact page', function(){
assert($('a[href="/contact"]').length);
});
});
This is my 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');
});
});
This is my main template file (handlebars)
<!doctype html>
<html>
<head>
<title>Random Pixel Media</title>
{{#if showTests}}
<link rel="stylesheet" href="/vendor/mocha">
{{/if}}
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</head>
<body>
<header><a href="/"><img src="/img/logo.png" alt="Random Pixel Logo" /></a></header>
{{{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>
</html>
According to the book, I should be seeing 2 suites and 1 failure when I visit the about page, but as I stated, I see a blank bullet point, passes:0 and fails:0 Any help to understand what I'm missing would be greatly appreciated.