骨干节点不工作(无头 TDD/开发)

发布于 2024-12-10 07:19:23 字数 1648 浏览 0 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

末骤雨初歇 2024-12-17 07:19:23

好的,我可以通过让节点执行要求来实现此工作:

    jQuery = $ = require("jquery");
    requirejs([ 'json2', 'underscore', 'backbone', "storydesk", ]);

现在,我需要插入一个Sinon fakeServer,看看如何

Ok, I was able to get this working by having node do the require:

    jQuery = $ = require("jquery");
    requirejs([ 'json2', 'underscore', 'backbone', "storydesk", ]);

Now, I need to plug in a Sinon fakeServer and see how

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文