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

Unit testing

7 Answers 884 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Phil
Top achievements
Rank 1
Phil asked on 02 Apr 2013, 07:52 AM
where can I find some documentation / examples with Qunit or Jasmine for something such as testing if data is bound to a grid? or upon selecting a row, data is present?

7 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 02 Apr 2013, 09:01 AM
Hello Phil,

 We don't currently have documentation for unit testing the Kendo UI widgets. It should be very simple to make assertions though. Here is a sample QUnit test which checks if the grid is bound to a data source:
http://jsbin.com/oholod/1/edit

All the best,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Phil
Top achievements
Rank 1
answered on 02 Apr 2013, 02:35 PM
What if my widgets were using wrappers such as MVC and I wanted to seperate the unit testing code into a seperate js file?
0
Atanas Korchev
Telerik team
answered on 02 Apr 2013, 02:50 PM
Hello Phil,

You can move the QUnit test from my example in a separate file and it should still work.

If you want to use an existing grid (one rendered by MVC) simply get its instance in the unit test and make the assertions:


test("the grid creates a row for every item in the data source", function() {
  var dom = $("#grid"); // get reference to the grid output by the mvc wrapper

  // assert  the number of table rows
  equal(dom.find("tbody > tr").length, 1);
});

Kind regards,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Phil
Top achievements
Rank 1
answered on 02 Apr 2013, 03:00 PM
I have a grid.cshtml file with this in it

@(Html.Kendo().Grid(Model.SomeModel)
.Name("NewGrid")
.DataSource(dataSource => dataSource
    .Ajax()
    .ServerOperation(false)
)

in a seperate grid_tests.js file

test("rows are available", function () {
    var dom = $("#NewGrid");
    equal(dom.find("tbody > tr").length, 1);
});

If I were to load grid.cshtml directly I'd see like 20 rows

Qunit comes back as 0
0
Atanas Korchev
Telerik team
answered on 02 Apr 2013, 03:17 PM
Hi Phil,

Grid ajax binding happens asynchronously and the qunit test is executed before the grid finishes binding. You can use an asynchronous QUnit tests: http://jsbin.com/oholod/3/edit

Regards,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Phil
Top achievements
Rank 1
answered on 10 Apr 2013, 02:03 AM
Thanks.

Could you also provide a Jasmine example of the same thing?
0
Atanas Korchev
Telerik team
answered on 10 Apr 2013, 06:53 AM
Hi Phil,

 Unfortunately I am not familiar with Jasmine and I cannot provide an example for this. Perhaps you can use the same approach with Jasmine provided that it supports asynchronous tests.

Regards,
Atanas Korchev
the Telerik team
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
Phil
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Phil
Top achievements
Rank 1
Share this question
or