I'm writing jasmine test cases for my validation function. This is the code for my function.
function validateCardNum(){
var cardEntered = $('#cardNum').val();
var cTypeVal = $('#cType').val();
if(cTypeVal === 'visa'){
var reg = /^4\d{15}$/;
if (!reg.test(cardEntered)) {
showError('#cardNum',errorMsg);
return false;
};
}
}
And this is the code I'm writing to test it:
describe('VISA Card Validations', function() {
$('#cType').val() = 'visa';
it('should not validate empty CC number', function() {
$('#cardNum').val() = '';
expect(validateCardNum().toBe(false));
});
});
When I write this, I get this error:
ReferenceError: Invalid left-hand side in assignment
My question is how can I assign testing values to my input fields to test different case scenarios.
I was using wrong syntax for changing value of input fields. I used this code, and it worked like charm!
describe('VISA Card Validations', function() {
$('#cType').val('visa');
it('should not validate empty CC number', function() {
$('#cardNum').val('');
expect(validateCardNum()).toBe(false);
});
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.