如何测试fullCalendar已使用Konacha初始化

时间:2013-11-25 15:51:48

标签: jquery fullcalendar konacha

我在Rails应用程序中使用fullcalendar,并希望使用Konacha测试我正在使用它的页面。

在名为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正在初始化的正确方向吗?

1 个答案:

答案 0 :(得分:0)

我使用mocha附带的done回调来解决这个问题。问题是fullcalendar需要一些时间来渲染,但是我的测试立即开始,所以没有时间来追加fc类。换句话说,我的代码是异步的,我的测试不是。以下代码有效:

it('renders fullCalendar plugin', function(done) {
    $('#konacha').fullCalendar();
    done();
    $('.fc').should.exist;
});