Jquery 我能用Jasmine更改复选框的状态吗?
我正在尝试编写一个测试,在选中复选框后检查一个值,但它始终返回一个失败的测试 我认为这就像使用jQuery将其值设置为checked一样简单,但它似乎不起作用 我的输入附带了一个更改事件:Jquery 我能用Jasmine更改复选框的状态吗?,jquery,karma-jasmine,Jquery,Karma Jasmine,我正在尝试编写一个测试,在选中复选框后检查一个值,但它始终返回一个失败的测试 我认为这就像使用jQuery将其值设置为checked一样简单,但它似乎不起作用 我的输入附带了一个更改事件: $("input#p1").change(function() { pprompts.settings.aiGoesFirst = $(this).is(":checked"); }); 我的测试: it('should allow the user to choose who goes first
$("input#p1").change(function()
{
pprompts.settings.aiGoesFirst = $(this).is(":checked");
});
我的测试:
it('should allow the user to choose who goes first', function()
{
// the user goes first by default - PASSES
expect(pprompts.settings.aiGoesFirst).toBe(false);
// trigger the checkbox for ai to go first and check if AI is going first - FAILS
$("input#p1").attr("checked","checked");
expect(pprompts.settings.aiGoesFirst).toBe(true);
});
任何指导都将不胜感激。我认为选中的设置不会触发更改事件。例如,请看:谢谢你。我已经更新了脚本以更改属性,然后触发更改,但仍然失败。