【发布时间】:2012-08-06 14:57:05
【问题描述】:
我在使用jasmine-node 和mocha(使用zombie)测试我的应用程序时遇到问题。关键是angular 不适用于此测试环境 - 当browser.visit "http://localhost:3000/" 它只显示布局,并且不呈现任何模板link。我猜javascript根本不在浏览器中运行(我的意思是僵尸对象)。 My test 有没有办法让它工作?还是问题不一样?
在我从另一个项目 spec 复制的 jasmine 规范中发生错误:
/home/alder/Node/angular-express-coffee/spec/app_spec.coffee:12
throw error;
^
ReferenceError: angular is not defined
at /js/services.js:4:3
at /js/services.js:6:4
in /js/services.js
所以我猜 javascript 也不起作用。
更新: 我添加了调试选项及其显示的内容:
➜ angular-express-coffee git:(master) ✗ mocha --require should --compilers coffee:coffee-script --colors -R spec --ui bdd
Given I am a new user
When I visit the home page
Zombie: GET http://localhost:3000/newPost => 200
Zombie: GET http://localhost:3000/ => 200
Zombie: GET http://localhost:3000/js/lib/jquery-1.7.2.min.js => 200
Zombie: GET http://localhost:3000/js/lib/bootstrap.min.js => 200
Zombie: GET http://localhost:3000/js/lib/angular.min.js => 200
Zombie: GET http://localhost:3000/js/app.js => 200
Zombie: GET http://localhost:3000/js/controllers.js => 200
Zombie: Unexpected token ILLEGAL SyntaxError: Unexpected token ILLEGAL
in /js/controllers.js
Zombie: GET http://localhost:3000/js/lib/jquery-1.7.2.min.js => 200
Zombie: Unexpected token ILLEGAL SyntaxError: Unexpected token ILLEGAL
in /js/lib/jquery-1.7.2.min.js
Zombie: GET http://localhost:3000/js/filters.js => 200
Zombie: GET http://localhost:3000/js/directives.js => 200
Zombie: Unexpected token ILLEGAL SyntaxError: Unexpected token ILLEGAL
in /js/directives.js
Zombie: Unexpected token ILLEGAL SyntaxError: Unexpected token ILLEGAL
in /js/filters.js
Zombie: GET http://localhost:3000/js/lib/bootstrap.min.js => 200
Zombie: Unexpected token ILLEGAL SyntaxError: Unexpected token ILLEGAL
in /js/lib/bootstrap.min.js
Zombie: GET http://localhost:3000/js/lib/angular.min.js => 200
Zombie: Unexpected token ILLEGAL SyntaxError: Unexpected token ILLEGAL
in /js/lib/angular.min.js
Zombie: GET http://localhost:3000/js/services.js => 200
Zombie: GET http://localhost:3000/js/filters.js => 200
Zombie: GET http://localhost:3000/js/directives.js => 200
Zombie: GET http://localhost:3000/js/controllers.js => 200
Zombie: GET http://localhost:3000/js/app.js => 200
Zombie: Unexpected token ILLEGAL SyntaxError: Unexpected token ILLEGAL
in /js/app.js
Zombie: Unexpected token ILLEGAL SyntaxError: Unexpected token ILLEGAL
in /js/controllers.js
Zombie: Unexpected token ILLEGAL SyntaxError: Unexpected token ILLEGAL
in /js/directives.js
Zombie: Unexpected token ILLEGAL SyntaxError: Unexpected token ILLEGAL
in /js/filters.js
Zombie: GET http://localhost:3000/js/services.js => 200
也许是coffeescript 中的问题,但我已经添加了mocha 选项。有没有什么方法可以在没有 Angular 团队传播的 JsTestDriver 的情况下测试 Angular 应用程序。
已更新。
我已将错误断言更改为browser.errors.should.be.empty,它向我显示了一个错误:
1) Given I am a new user When I visit the home page Then browser status shold be ok:
AssertionError: expected [ [Error: Unexpected token ILLEGAL],
[Error: Unexpected token ILLEGAL],
[Error: Unexpected token ILLEGAL],
[Error: Unexpected token ILLEGAL],
[Error: Unexpected token ILLEGAL],
[Error: Unexpected token ILLEGAL],
[Error: Unexpected token ILLEGAL],
[Error: angular is not defined] ] to be empty
at Object.empty (/home/alder/Node/angular-express-coffee/node_modules/should/lib/should.js:229:10)
at Context.<anonymous> (/home/alder/Node/angular-express-coffee/test/app_test.coffee:31:40)
at Test.Runnable.run (/usr/lib/node_modules/mocha/lib/runnable.js:184:32)
at Runner.runTest (/usr/lib/node_modules/mocha/lib/runner.js:300:10)
at Runner.runTests.next (/usr/lib/node_modules/mocha/lib/runner.js:346:12)
at next (/usr/lib/node_modules/mocha/lib/runner.js:228:14)
at Runner.hooks (/usr/lib/node_modules/mocha/lib/runner.js:237:7)
at next (/usr/lib/node_modules/mocha/lib/runner.js:185:23)
at Runner.hook (/usr/lib/node_modules/mocha/lib/runner.js:205:5)
at process.startup.processNextTick.process._tickCallback (node.js:244:9)
最后更新:
问题出在资产管道中,Zombie 浏览器的所有js 都被禁用。现在我从咖啡换成 js,它可以工作了。但我更喜欢咖啡,所以如果有人能解决这个问题,我将不胜感激。
【问题讨论】:
-
嗨,你说的“js 被僵尸禁用”是什么意思?我有完全相同的问题,我发现的唯一解决方法是使用
express.static提供 JS 文件(不理想)。 stackoverflow.com/questions/12700152/…
标签: node.js coffeescript angularjs mocha.js zombie.js