我在Rails应用程序中使用满历,并希望测试我在使用科纳查时使用的页面。
在一个名为fullcal_init的文件中,我有以下代码
jQuery(document).ready(function($) {
$('#calendar').fullCalendar({
//do stuff with fullCalendar
});
});生成<div id="calendar" class="fc fc-ltr" ... ></div>
我试图用以下代码来测试它:
#test_helper
//= require jquery
//= require chai-jquery
//= require "application"
...
#my_tests.js
//= require "test_helper"
var $ = jQuery
"use strict";
describe('fullcalendar_init', function() {
it('renders the fullCalendar event stream', function() {
('#konacha').fullCalendar;
assert.ok($('#konacha').should.have.class('fc'));
});
});但是,这是行不通的-- Konacha测试体没有任何类附加到它。关于使用Konacha的文档不多(特别是在backbone.js上下文之外)--有人能为我指出如何测试fullcalendar是否被初始化的正确方向吗?
发布于 2013-11-27 10:26:29
我通过使用done随附的mocha回调来实现这个功能。问题是fullcalendar需要一些时间来呈现,但我的测试立即启动,因此没有时间追加fc类。换句话说,我的代码是异步的,而我的测试不是异步的。以下代码起作用:
it('renders fullCalendar plugin', function(done) {
$('#konacha').fullCalendar();
done();
$('.fc').should.exist;
});https://stackoverflow.com/questions/20197307
复制相似问题