This is a migrated thread and some comments may be shown as answers.

AngularJS Jasmine Unit Testing Support

6 Answers 508 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
mosswgreentea
Top achievements
Rank 1
mosswgreentea asked on 23 Dec 2014, 06:17 PM
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.

6 Answers, 1 is accepted

Sort by
0
Petyo
Telerik team
answered on 24 Dec 2014, 10:18 AM
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!
 
0
mosswgreentea
Top achievements
Rank 1
answered on 24 Dec 2014, 04:37 PM
Hi,

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

Thanks,
Arvind
0
mosswgreentea
Top achievements
Rank 1
answered on 29 Dec 2014, 11:05 PM
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?

0
Alex Gyoshev
Telerik team
answered on 30 Dec 2014, 09:28 AM
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!
 
0
mosswgreentea
Top achievements
Rank 1
answered on 31 Dec 2014, 05:11 PM
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?
0
Petyo
Telerik team
answered on 01 Jan 2015, 11:31 AM
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!
 
Tags
General Discussions
Asked by
mosswgreentea
Top achievements
Rank 1
Answers by
Petyo
Telerik team
mosswgreentea
Top achievements
Rank 1
Alex Gyoshev
Telerik team
Share this question
or