骨干节点不工作(无头 TDD/开发)
我正在尝试使用 Vows (BDD) 来测试 MyApp,使用 Backbone (需要 JQuery)。我想使用 NodeJS 进行无头开发,但当我尝试执行 B) 中的代码时,出现错误 A)。基本上,JQuery 对象不在 Backbone 库的范围内。但一切都是必需的/导入的,如 C) 中一样。有人成功让 Backbone 在 NodeJS 上工作吗?我知道 nodechat (下载代码并尝试运行它)和 服务器博客文章上的骨干模型,示例,但它们不适用于我设置的内容。我正在使用 Node(v0.5.10-pre) 和 Backbone v(0.5.3)。
A)
TypeError: Cannot call method 'ajax' of undefined at [object Object]. (/js/backbone.js:1082:14) ...
B)
var fubar = new myapp.models.Fubar(); // this class already has a url set fubar.fetch();
C)
var requirejs = require('js/r.js'); requirejs.config({ nodeRequire: require, baseUrl: 'js', }); var vows = require('vows'); var assert = require('assert'); //** Hack to get a Window object for JQuery var zombie = require("zombie"); var browser = new zombie.Browser; browser.window.location = "http://localhost:3000"; window = browser.window; //** Hack due to Sinon not being designed to work in NodeJS; putting some stubs to get it working sinon = require('sinon'); var xhr = require("sinon/lib/sinon/util/fake_xml_http_request"); var fakeServer = require("sinon/lib/sinon/util/fake_server").fakeServer; requirejs([ 'jquery-1.6.4', 'json2', 'underscore', 'backbone', '_**myapp**_', ]);
我假设下划线已被拉入并正确使用。但我认为我还没有走得足够远来确认。
谢谢
I'm trying to use Vows (BDD) to test MyApp, using Backbone (which needs JQuery). I want to use NodeJS to get headless development, but I'm getting the error A), when I try to execute the code in B). Basically, the JQuery object is not in the scope of the Backbone library. But everything was require'd / imported as in C). Does anyone successfully have Backbone working on NodeJS. I'm aware of the nodechat (downloaded the code and tried to run it) and backbone models on server blog post, examples, but they are not working with what I've set up. I'm using Node(v0.5.10-pre) and Backbone v(0.5.3).
A)
TypeError: Cannot call method 'ajax' of undefined at [object Object]. (/js/backbone.js:1082:14) ...
B)
var fubar = new myapp.models.Fubar(); // this class already has a url set fubar.fetch();
C)
var requirejs = require('js/r.js'); requirejs.config({ nodeRequire: require, baseUrl: 'js', }); var vows = require('vows'); var assert = require('assert'); //** Hack to get a Window object for JQuery var zombie = require("zombie"); var browser = new zombie.Browser; browser.window.location = "http://localhost:3000"; window = browser.window; //** Hack due to Sinon not being designed to work in NodeJS; putting some stubs to get it working sinon = require('sinon'); var xhr = require("sinon/lib/sinon/util/fake_xml_http_request"); var fakeServer = require("sinon/lib/sinon/util/fake_server").fakeServer; requirejs([ 'jquery-1.6.4', 'json2', 'underscore', 'backbone', '_**myapp**_', ]);
I'm assuming underscore is pulled in and used correctly. But I don't think I've gotten far enough to confirm.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,我可以通过让节点执行要求来实现此工作:
现在,我需要插入一个Sinon fakeServer,看看如何
Ok, I was able to get this working by having node do the require:
Now, I need to plug in a Sinon fakeServer and see how