- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
运行下面的 Jasmine 测试(1),测试成功,但我面临主测试页面的递归加载。
这是我的测试 (1),这是我运行测试的模块 (2):
有什么想法吗?我该如何解决这个问题?
附言:
该问题仅与 Chrome 和 Safari 浏览器有关。
这是一个例子:jsfiddle.net/shioyama/EXvZY
(1)
describe('When Submit button handler fired', function () {
beforeEach(function () {
spyOn(MyView.prototype, 'submitForm');
this.view = new MyView();
this.view.render();
this.view.$el.find('form').submit();
});
it('submitForm should be called', function () {
expect(MyView.prototype.submitForm).toHaveBeenCalled();
});
});
(2)
var MyView = Backbone.View.extend({
events: {
'submit form' : 'submitForm'
},
submitForm: function (event) {
event.preventDefault();
// some code
}
});
最佳答案
Backbone 使用委托(delegate)事件,这些事件在创建 View 时被绑定(bind)。您的 view.el 在创建时不包含表单,而是您在 render 方法中创建了一个表单。这就是提交委托(delegate)事件未被绑定(bind)的原因,而是您在页面上提交表单。该表单提交到相同的 URL,这会触发 Jasmine 套件再次运行,从而导致循环。
如果稍微修改一下代码,您会发现此版本可以正常工作,因为
关于javascript - 使用 Jasmine 测试 Backbone View 时,浏览器页面不断刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11986605/
如果这不是一个错误,那就是另一个错误。如果不是那样的话,那就是别的东西了。我觉得我的项目已经改变了很多,现在只是试图解决代码签名问题,结果一切都搞砸了。我严格按照说明进行操作,但出现错误,例如当前的“
我不确定是否有一些我不知道的内置变量或规则,或者 make 是否有问题,或者我只是疯了。 对于我的一个项目,我有一个如下的 makefile: CC=g++ CFLAGS=-O3 `libpng-co
我有大约 10 个 div,它们必须不断翻转,每个 div 延迟 3 秒 这个 codrops 链接的最后一个效果是我正在寻找的,但无需单击 div http://tympanus.net/Devel
我如何使用 jQuery 持续运行 PHP 脚本并每秒获取响应,以及将鼠标上的少量数据发送到同一脚本? 我真的必须添加一些随机扩展才能让这么简单的计时器工作吗? 最佳答案 To iterate is
JBoss 4.x EJB 3.0 我见过如下代码(大大简化): @Stateless @TransactionAttribute(TransactionAttributeType.NOT_SUPPO
使用 PHPStorm,我试图忽略每次尝试进行 git 提交时 pop 的 workspace.xml。 我的 .gitignore 看起来像: /.idea/ .idea/workspace.xml
我是一名优秀的程序员,十分优秀!