0

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

4

1 回答 1

0

我通过done使用mocha. 问题是fullcalendar渲染需要一些时间,但我的测试立即触发,因此没有时间fc附加该类。换句话说,我的代码是异步的,而我的测试不是。以下代码有效:

it('renders fullCalendar plugin', function(done) {
    $('#konacha').fullCalendar();
    done();
    $('.fc').should.exist;
});
于 2013-11-27T10:26:29.040 回答