javascript - 向 jasmine 添加固定装置/设置 Jasmine-Jquery

标签 javascript tdd coffeescript jasmine jasmine-jquery

我正在尝试使用 jasmine-jquery 插件:https://github.com/velesin/jasmine-jquery .在文档中它说:

Simply download jasmine-jquery.js from the downloads page and include it in your Jasmine's test runner file (or add it to jasmine.yml file if you're using Ruby with jasmine-gem). Remember to include also jQuery library as jasmine-jquery relies on it.

我正在尝试使用此插件为 coffeescript 单页 HTML5 Canvas 应用程序的 coffeescript 中的 jasmine 测试添加固定装置。我正在使用 jasmine 的 jasmine-node 版本使用 node.js 运行我的 jasmine 测试 我对上述说明的问题是我没有看到要编辑的 jasmine 测试运行器文件,因此我无法调用来自此插件的方法,例如我的规范中的 load_fixtures。

我当前的项目目录结构是

coffescript/shape.coffee
index.html (An html file I would ideally like to use for my tests)
javascript/shape.js (The outputted coffeescript)
spec/shape.spec.coffee
spec/jasmine-jquery-1.3.1.js (The plugin)

非常感谢任何见解,因为我花了几个小时试图让它正常工作。如果你知道一个不同的测试框架和固定装置,它会更容易为 coffeescript 项目设置,这也很受欢迎。谢谢!

最佳答案

您尝试使用的库假定您在 html 页面中使用 jasmine。它和 jquery 都不能与 jasmine-node 一起工作。

jQuery 不能在节点上工作,因为它需要浏览器的 DOM api。有一些libraries that mock the DOM for node这可能会给你你所需要的。

关于javascript - 向 jasmine 添加固定装置/设置 Jasmine-Jquery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7734979/

相关文章:

javascript - Mongoose 查询返回错误,但错误是我正在寻找的结果

javascript - 如何判断Javascript Q deferred()是否已经执行完链中的所有函数

javascript - D3.js ResizeObserver 呈现问题。调整大小后未删除轴

java - 如何在 Wicket 中测试链接的文本

Clojure.spec:如何规范对随机变化敏感的数据结构?

javascript - 计算浏览器滚动条的大小

jquery - 如何选择和隐藏 HTML 文件 (DOM) 中除前 5 个元素之外的所有元素

javascript - JavaScript 支持百分比单位吗?

TDD 和测试数据

jquery - 如何使用 jquery 选择器搜索列表