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