using node with JADE as view engine. Im just trying to get into some page testing following a book called "Web Development with Node and Express."
Im getting following Error:
Cannot call method 'ui' of undefined
When i try to call mocha.ui
58| script(type='text/javascript' src='/mocha/mocha.js')
59| script(type='text/javascript' src='/chai/chai.js')
> 60| -mocha.ui('tdd');
61| -var assert = chai.assert;
62| script(type='text/javascript' src='/qa/global-tests.js')
63| -if(pageTestScript){
Whole call:
//Page Tests + Global Tests
-if(showTests){
div(id="mocha")
script(type='text/javascript' src='/mocha/mocha.js')
script(type='text/javascript' src='/chai/chai.js')
-mocha.ui('tdd');
-var assert = chai.assert;
script(type='text/javascript' src='/qa/global-tests.js')
-if(pageTestScript){
script(src= pageTestScript)
-}
-}
My Path structure is:
node_modules
->chai
->->chai.js
->mocha
->->mocha.js
Also the visibility for the node_modules are set:
app.use(express.static(__dirname + '/node_modules'));
Checking via firebug, following css is accessable:
link(rel='stylesheet', href='/mocha/mocha.css')
Tried moving js files to different folders, changed script calls, googled.
Thank you very much.
It looks like you want mocha
to be available to jade as a variable by using a script tag. You seem confused between variables in front-end and back-end. The mocha variable you are using is a backend variable supplied by node. It has absolutely no relation with the mocha.js in your script tag.
For lines beginning with -
or =
, jade evaluates these and replaces them with their values server-side. Script tags get evaluated in browser. All it does is convert something like
script(src="hello.js)
to
<script src="hello.js">
Jade DOES NOT run the scripts mentioned in script tags.
ADDED AFTER SOLUTION (handles mocha tests in client):
-if(showTests){
div(id="mocha")
script(type='text/javascript' src='/mocha/mocha.js')
script(type='text/javascript' src='/chai/chai.js')
script(type='text/javascript').
mocha.ui('tdd');
var assert = chai.assert;
script(type='text/javascript' src='/qa/global-tests.js')
script(type='text/javascript').
console.log('Test console output');
-if(pageTestScript){
script(src= pageTestScript)
-}
script(type='text/javascript').
mocha.run();
-}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.