Problem with autocomplete datasource when unit testing

2 posts, 0 answers
  1. Keir
    Keir avatar
    2 posts
    Member since:
    Oct 2012

    Posted 18 Oct 2012 Link to this post

    Hi,

    I'm attempting to unit test(using Jasmine) an angular directive containing a call to jquery('element').kendoAutoComplete(...). We are using jstestdriver to launch our unit tests in a chrome browser, and this also allows us to breakpoint the javascript and create watch expressions.
    We have added the kendo.all.min.js and kendo.core.js scripts to the jsTestDriver configuration and they are visible when the browser is open during the unit test runs.
    My problem is, that at the point of creating the xyz = new kendo.data.DataSource(...) the DataSource has not been initialized and is tripping up my unit tests. I am able to create a watch expression(in Chrome) on the kendo.data portion, so it seems that some of kendo is loading and working. We do have other tests running on things like the kendoDatePicker and those run fine.

    I have tried searching for ways to mock out the DataSource, but it would help if I could see the code behind the object to know what needs to be mocked however I have been unsuccessful in finding the source for the kendo DataSource object(can someone help me with this?).

    The actual code evaluates properly when deployed in the main application and doesnt have this issue. Could this be as a result of the DataSource not being attached due to missing code/a missing function call? Is there some way of me manually getting it to be attached?
  2. Keir
    Keir avatar
    2 posts
    Member since:
    Oct 2012

    Posted 19 Oct 2012 Link to this post

    After doing some fiddling, it turns out that due to all the javascript being on one line in the kendo.all.min.js, part of the script was being cut off and not loading properly, thus attempting to use the DataSource resulted in an undefined exception(it wasn't there).

    So in order to fix this issue you should run your tests on the un-minified kendo.all.js or if you don't have this, auto format the javascript in Netbeans which will split everything onto new lines.

    The benefits of this are:
     - its easier to trace through the javascript when trying to debug unit test issues,
     - the javascript is not cut off, and you don't run into function not found/undefined issues
Back to Top