Konacha Javascript规范中的Stub单选按钮

时间:2014-09-18 16:25:41

标签: javascript konacha

这是我的Javascript:

if $("#payment_cc:checked").length > 0
  path = "/orders"
  if @get('tokenize')
    @_submitWithToken(obj, path)
  else
    @_submitWithCC(obj, path)
else
  path = "/orders/paypal"
  @_submitWithCC(obj, path)

我正在尝试在我的Javascript规范中进行模拟,以便我可以在以下时间进行测试:

$("#payment_cc:checked").length == 1
$("#payment_cc:checked").length == 0

如何在我的Konacha测试中设置length的{​​{1}}?

1 个答案:

答案 0 :(得分:0)

不要设置jQuery元素选择的length,只需设置要手动检查的单选按钮,如下所示:

describe('when the radio is selected', function() {
    beforeEach(function() {
        $('#payment_cc').attr('checked', true);
    });

    it('should do something', function() {
        // Assert that the submission went the way you wanted it to
    });
});