- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我尝试使用rendr(客户端和服务器中的 Backbone )创建一个web应用程序并尝试实现一些单元测试。
有没有办法在 Mocha 中运行集合获取单元测试?我想使用 sinon-chai 来模拟 mocha 中的 ajax 请求。但是当我尝试以这种方式 stub $“ajax” 时会发生错误,
var chai = require("chai");
var rekuire = require("rekuire");
var sinon = require("sinon");
var $ = require("jquery"); //because this is node-jquery, we don't have ajax function.
chai.use(require("sinon-chai"));
require("chai").should();
require("mocha-sinon");
var Books = rekuire("app/collections/books");
describe("Books interaction with REST API", function() {
it("should load using the API", function(){
//TypeError: Cannot stub non-existent own property ajax
this.ajax_stub = this.sinon.stub($, "ajax").yieldsTo("success", [
{
count: 20,
"books": [
{
title: "Google1",
author: ["author1", "author2"]
},
{
title: "Google2",
author: ["author3", "author4"]
}
]
}
]);
this.books = Books.fetch();
this.books.should.have.length(2);
this.ajax_stub.restore();
});
});
我的问题是,当我们在 mocha 中运行单元测试时,有没有办法 stub $.ajax 函数?
最佳答案
对于渲染:
测试存在一些问题。模型/集合获取实际上使用 async.parallel,而不是 $.ajax。
此外,我不建议专门测试 .fetch
,除非您要覆盖它。该函数已经在 Rendr 本身内部进行了测试,因此该测试不会给您带来太多实用性。如果您要覆盖,我建议仅删除 collection.fetch
函数,并使用该 yield 而不是 $
。
关于javascript - Mocha 运行 rendr 集合 ajax 单元测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30998044/
我在 Rendr 应用程序的 Controller 中收到 500 ReferenceError: localStorage is not Defined 。我尝试从 localStorage 获取我
我正在使用 Qtextdocument 生成报告,我以编程方式准备了一个表字符串作为 html 字符串,但是当我渲染它时,边框没有显示(图 2) 在浏览器中我得到(图片 1) 但在我的 Qt 应用程序
假设我正在构建一个博客,其中主页呈现一个博客文章列表。我的问题是如何将模型传递给每个子帖 subview ? 我有一个遍历集合的 index.hbs {{#forEach models}} {
看起来 Backbone.Marionette View 为事件等操作 DOM,所以我猜这不像更改基类引用那样微不足道,例如Backbone.View 到 BaseView。 有没有人解决过这个问题?
我尝试使用rendr(客户端和服务器中的 Backbone )创建一个web应用程序并尝试实现一些单元测试。 有没有办法在 Mocha 中运行集合获取单元测试?我想使用 sinon-chai 来模拟
我想知道是否有人一直在使用 AirBnB Rendr,它是否稳定且可以用于商业项目,或者它是否仍在发生很大变化? 我正在开发一个可以同时运行客户端和基于服务器的网站,这意味着我需要能够呈现基于服务器和
我已经构建并运行了 Rendr's example apps在 Ubuntu 13.10 上使用 Node v0.8.6。当我点击 Repos 或 Users 链接时,我收到 HTTP 502 - B
我是一名优秀的程序员,十分优秀!