[英]Cannot call method 'ui' of undefined
using node with JADE as view engine. 使用带有JADE的节点作为视图引擎。 Im just trying to get into some page testing following a book called "Web Development with Node and Express."
我只是试着按照一本名为“使用Node和Express进行Web开发”的书进行一些页面测试。
Im getting following Error: 我得到以下错误:
Cannot call method 'ui' of undefined
When i try to call mocha.ui 当我试着打电话给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: 此外,还设置了node_modules的可见性:
app.use(express.static(__dirname + '/node_modules'));
Checking via firebug, following css is accessable: 通过firebug进行检查,可以访问以下css:
link(rel='stylesheet', href='/mocha/mocha.css')
Tried moving js files to different folders, changed script calls, googled. 尝试将js文件移动到不同的文件夹,更改了脚本调用,google搜索。
Thank you very much. 非常感谢你。
It looks like you want mocha
to be available to jade as a variable by using a script tag. 看起来您希望通过使用脚本标记将
mocha
作为变量用于jade。 You seem confused between variables in front-end and back-end. 你似乎对前端和后端的变量感到困惑。 The mocha variable you are using is a backend variable supplied by node.
您使用的mocha变量是节点提供的后端变量。 It has absolutely no relation with the mocha.js in your script tag.
它与脚本标记中的mocha.js完全没有关系。
For lines beginning with -
or =
, jade evaluates these and replaces them with their values server-side. 对于以
-
或=
开头的行,jade会对这些行进行求值,并将其替换为服务器端的值。 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. Jade不会运行脚本标记中提到的脚本。
ADDED AFTER SOLUTION (handles mocha tests in client): 在解决方案之后添加(在客户端处理mocha测试):
-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();
-}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.