Question

I'm using fullcalendar in a Rails application and want to test the pages that I'm using it on using Konacha.

In a file called fullcal_init, I have the following (working) code

jQuery(document).ready(function($) {

    $('#calendar').fullCalendar({

        //do stuff with fullCalendar

    });

});

which generates <div id="calendar" class="fc fc-ltr" ... ></div>

I'm trying to test it with the following code:

#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'));
    });

});

this isn't working however - the Konacha test body doesn't have any classes appended to it. There's not a lot of documentation about using Konacha (especially outside of a backbone.js context) - can anyone point me in the right direction as to how to test that fullcalendar is being initialized?

Was it helpful?

Solution

I got this working by using the done callback that comes with mocha. The problem was that fullcalendar takes some time to render, but my test was firing immediately, so there was no time for the fc class to be appended. Put another way, my code is asynchronous and my test was not. The following code works:

it('renders fullCalendar plugin', function(done) {
    $('#konacha').fullCalendar();
    done();
    $('.fc').should.exist;
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top