Skip to content

Commit 3f23f5e

Browse files
author
Zach Shepherd
committed
Mask: add unit tests for optional section
1 parent 8cca5e5 commit 3f23f5e

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

tests/unit/mask/mask_methods.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,25 @@ test( "value: able to get (and set) raw values", function() {
2525
equal( input.mask( "value" ), "123456", "Raw value read correctly" );
2626
});
2727

28+
test( "value: able to get (and set) raw values with optional section", function() {
29+
expect( 5 );
30+
var input = $( "#mask1" ).val("1234").mask({
31+
mask: "(999) 999-9999?x9999",
32+
});
33+
34+
equal( input.mask('value'), "1234", "Reading initial value" );
35+
36+
input.mask( "value", "123456" );
37+
38+
equal( input.val(), "(123) 456-____", "Raw value set properly" );
39+
equal( input.mask( "value" ), "123456", "Raw value read correctly" );
40+
41+
input.mask( "value", "12345678901234" );
42+
43+
equal( input.val(), "(123) 456-7890x1234", "Raw value with optional set properly" );
44+
equal( input.mask( "value" ), "12345678901234", "Raw value read correctly" );
45+
});
46+
2847
test( "valid: returns true when all required placeholders are filled", function() {
2948
expect( 2 );
3049
var input = $( "#mask1" ).mask({

tests/unit/mask/mask_options.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ test( "mask", function() {
4545
equal( input.val(), "(123)4__-____", "Mask changed" );
4646
});
4747

48+
test( "mask with optional input", function() {
49+
expect( 1 );
50+
var input = $( "#mask1" ).val("1234").mask({
51+
mask: "(999) 999-9999?x9999",
52+
});
53+
54+
equal( input.val(), "(123) 4__-____", "Initial value" );
55+
});
56+
4857
test( "mask option parser", 1, function() {
4958
var defs = {
5059
hh: function( value ) {

0 commit comments

Comments
 (0)