这就是我正在做的事情
requirejs(['jquery', 'application'], function($, app){
describe('View Products List', function(){
// All test in this test suite fails
it('Products list should be present', function(done) {
$('.productlist').length.should.equal(1);
return done();
});
it('product list should be have a checkbox for product selection', function(done) {
$('.productlist td:first input[type=checkbox]').length.should.equal(1);
return done();
});
it('product name should be anchor which could be clickable', function(done) {
$('.productlist td:first a').length.should.equal(1);
return done();enter code here
});
it('Should show product details on click of product name', function(done) {
$('.productlist td:first a').click();
$('.editproduct').length.should.equal(1);
return done();
});
});
});
var Products = new Backbone.View.extend({
tagName : 'div'
template : productsTemplate
render: function() {
$(this.el).html(this.template());
}
initialize: function() {
// some code
}
});
当我运行我的测试脚本并加载url #products时,产品视图将呈现给html正文。我希望测试用例检查视图生成的DOM元素。似乎测试首先运行,即在视图呈现dom元素之前,因此它失败了。我怎样才能确保在我的测试运行之前视图已完全呈现?
答案 0 :(得分:0)
在Mocha中,异步代码应包含在beforeEach
部分中,以确保它在测试之前执行。
在您的情况下,尝试重新渲染本节中的视图:
beforeEach(function() {
productListView.render();
});
describe('View Products List', function(){
it("...
...
您可以查看此帖子了解更多详情:http://lostechies.com/derickbailey/2012/08/17/asynchronous-unit-tests-with-mocha-promises-and-winjs/