lundi 28 mars 2016

Writing Unit Tests for Form Elements

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.

Aucun commentaire:

Enregistrer un commentaire