Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maxlength on field not working with Karma

I have a field with a maxlength of 6, but somehow the following way of entering data results in 7 chars being allowed:

<input type="text" name="myName" maxlength="6" ng-model="myModel">

this is the test bit:

input('myModel').enter('1111117');
expect(input('myModel').val()).toBe(111111);

and this is the result

expected 111111 but was "1111117"

I suppose this has to do with the model being used instead of the real field, but how would I test this then in Karma?

like image 213
Maarten Avatar asked Sep 30 '22 14:09

Maarten


1 Answers

The problem is caused because maxlength only limits the input from the user, and not the actual value of the input. For example, if you try to use jQuery's val() on your input, it would accept any length of the value.

I tried to simulate input in more sophisticated ways, like triggering keyboard events or third party tools, but with no success. It looks like any programmatic way to change the input's value, is not limited by maxlength.

like image 160
Yaron Schwimmer Avatar answered Oct 27 '22 20:10

Yaron Schwimmer