1

I'm using jasmine for my unit tests. I have a function that contains:

var startDate = $("#startDate").data("kendoDatePicker").value();

But when the unit test hits that line it errors out saying:

TypeError: Cannot read property 'value' of null

I've tried stuff like setting it

$("#startDate").data("kendoDatePicker").value = '12/25/2014';

but that results in "cannot set value of null"(or something along those lines)

and I've tried to spy on it, but in all honesty, my knowledge here is limited. I'm hoping I'm just missing some basic terminology in my google searches and someone will be able to help me.

How do I mock this or spy on it?

Thanks in advance!

EDIT:

I was able to "fix" it but I consider this "hacky" and would still like a better solution. I created a new html page called "tests.html" which contains:

<div style="visibility: hidden; height: 0">
    <input id="startDate" /> 
</div>

Then I referenced the file:

/// <reference path="tests.html" />

Then at the top of my unit test I added:

$('#startDate').kendoDatePicker({
    min: new Date()
});

And now it "works", but it's reading from an actual input box, which it shouldn't need...

Timothy
  • 1,198
  • 3
  • 10
  • 30
  • What is the engine running your jasmine tests? – Dalorzo Jan 02 '15 at 15:12
  • I think the issue here is you need to initialise "kendoDatePicker" element with some data. When you said you set it have you tried doing some different ways (http://api.jquery.com/data/) i.e. $( "#startDate" ).data( "kendoDatePicker", '12/25/2014' ); – AMadmanTriumphs Jan 02 '15 at 15:14
  • @Dalorzo not 100% sure what you're asking.. I'm using chutzpah in visual studio, so I'm just right clicking and selecting "Open in browser". Is this what you're asking? – Timothy Jan 02 '15 at 15:20
  • @ScottSellers that gives me the same result, "Cannot read property 'value' of null" – Timothy Jan 02 '15 at 15:24
  • @Timothy - this might help. How to set the date for your tests (http://stackoverflow.com/questions/25337509/set-today-date-to-kendo-datepicker) – AMadmanTriumphs Jan 02 '15 at 15:30
  • @ScottSellers That still doesn't work. Since it's a unit test, which doesn't load the actual html, the object doesn't really exist, which is why I'm getting the error. I need a way to mock it, or create a spy which can return a value, when it's called. – Timothy Jan 02 '15 at 15:46
  • @Timothy - ok, sorry. I am not sure i can help. Hope you get it sorted. – AMadmanTriumphs Jan 02 '15 at 15:52
  • @ScottSellers no worries. Thanks for your help! I was able to get a hackish fix in for now, which will work until I find something better. (see edit, if interested) – Timothy Jan 02 '15 at 15:55

0 Answers0