AngularJS Jasmine Unit Testing Support

7 posts, 0 answers
  1. mosswgreentea
    mosswgreentea avatar
    10 posts
    Member since:
    Dec 2009

    Posted 23 Dec 2014 Link to this post

    My projects are built using AngularJS and therefore I write my unit tests using Jasmine. I've been trying to write very simple unit tests for testing the kendo directives and they are all failing at a specific point. I've attached below a very simple test (taken from the kendo-labs code base).

    describe("basic tests", function () {
        beforeEach(function () {
            module("kendo.directives");
        });

        // kendoCalendar
        it('should create kendoCalendar widget', function () {
            inject(function ($rootScope, $compile, $timeout) {
                var element = $compile('<div><input id="calendar" kendo-calendar></div>')($rootScope);
                $rootScope.$apply();
                $timeout.flush();
                var dataRole = element.find('#calendar').data('role');
                expect(dataRole).toBe('calendar');
            });
        });
    });

    When I try to run this test, I get this error: TypeError: 'undefined' is not a function (evaluating 'i.is("select")') (line 42).

    Can somebody help me? If I am doing something wrong, could somebody give me a simple example using Jasmine.
  2. Petyo
    Admin
    Petyo avatar
    2444 posts

    Posted 24 Dec 2014 Link to this post

    Hi,

    the error usually occurs if you include the AngularJS script before the jQuery one.

    Regards,
    Petyo
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  3. mosswgreentea
    mosswgreentea avatar
    10 posts
    Member since:
    Dec 2009

    Posted 24 Dec 2014 in reply to Petyo Link to this post

    Hi,

    Thank you so much for the reply! That did it.

    Thanks,
    Arvind
  4. mosswgreentea
    mosswgreentea avatar
    10 posts
    Member since:
    Dec 2009

    Posted 29 Dec 2014 in reply to Petyo Link to this post

    This was working with a older version of kendoui. I recently downloaded the latest version of kendoui (2014.3.1119) and this is no longer working. How can I overcome this error?

  5. Alex Gyoshev
    Admin
    Alex Gyoshev avatar
    2527 posts

    Posted 30 Dec 2014 Link to this post

    Hello Arvind,

    Version 2014.3.1119 and newer of Kendo UI work against AngularJS 1.3, so you might need to upgrade it, too. 

    Regards,
    Alex Gyoshev
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  6. mosswgreentea
    mosswgreentea avatar
    10 posts
    Member since:
    Dec 2009

    Posted 31 Dec 2014 in reply to Alex Gyoshev Link to this post

    I included all the files (jquery, angular, kendoui.all.min) from the downloads for 2014.3.1119. When I try to execute the basic test describe above, I get this error: Error: No deferred tasks to be flushed.

    I narrowed it to this particular line: $timeout.flush();

    This was working when I was using 2014.2.1008 build. Do you have any idea what I am doing wrong? Can you provide a simple working unit test written in Jasmine?
  7. Petyo
    Admin
    Petyo avatar
    2444 posts

    Posted 01 Jan 2015 Link to this post

    Hi,

    we are not familiar with the Jasmine test framework and its AngularJS integration. Our tests are written in QUnit. In general, you may try removing the Kendo UI scripts from the setup and see if it still fails in the same manner, since the timeout call you point to does not seem to be in the Kendo UI code.

    If it the setup still fails, your best bet would be to contact the AngularJS support forums or post your case in Stack Overflow. 

    Regards,
    Petyo
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
Back to Top