Search code examples
jqueryqunitfuncunit

How to set an element's property using Funcunit in qunit window (test window)


I am using FuncUnit with qunit to test an application. I would like to set selected property of an option of <select> menu to be true .

In jQuery, I could do something like

$('select#id option:eq(0)').prop('selected', true).change();

to achieve this. But, in funcunit,

S('select#id option:eq(0)').prop('selected', true).trigger('change');

selector finds the element and just get (not set) the value of prop selected. I want to set prop of the element.


Solution

  • As per comment from funcunit team - A user wouldn't be able to set the property of an option, they would just know to perform some action such as a click, drag, etc.

    so to achieve this we need to do

    S.win.$('select#id option:eq(0)').prop('selected', true).trigger('change');
    

    This runs jquery on test window.