0

这是我的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 测试中设置lengthof ?$("#payment_cc:checked")

4

1 回答 1

0

无需设置lengthjQuery 元素选择,只需将单选按钮设置为手动检查,如下所示:

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
    });
});
于 2014-09-19T13:20:49.290 回答