Skip to content

Commit

Permalink
Mask: add unit tests for optional section
Browse files Browse the repository at this point in the history
  • Loading branch information
Zach Shepherd committed Oct 16, 2012
1 parent 8cca5e5 commit 3f23f5e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/unit/mask/mask_methods.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -25,6 +25,25 @@ test( "value: able to get (and set) raw values", function() {
equal( input.mask( "value" ), "123456", "Raw value read correctly" ); equal( input.mask( "value" ), "123456", "Raw value read correctly" );
}); });


test( "value: able to get (and set) raw values with optional section", function() {
expect( 5 );
var input = $( "#mask1" ).val("1234").mask({
mask: "(999) 999-9999?x9999",
});

equal( input.mask('value'), "1234", "Reading initial value" );

input.mask( "value", "123456" );

equal( input.val(), "(123) 456-____", "Raw value set properly" );
equal( input.mask( "value" ), "123456", "Raw value read correctly" );

input.mask( "value", "12345678901234" );

equal( input.val(), "(123) 456-7890x1234", "Raw value with optional set properly" );
equal( input.mask( "value" ), "12345678901234", "Raw value read correctly" );
});

test( "valid: returns true when all required placeholders are filled", function() { test( "valid: returns true when all required placeholders are filled", function() {
expect( 2 ); expect( 2 );
var input = $( "#mask1" ).mask({ var input = $( "#mask1" ).mask({
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/mask/mask_options.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ test( "mask", function() {
equal( input.val(), "(123)4__-____", "Mask changed" ); equal( input.val(), "(123)4__-____", "Mask changed" );
}); });


test( "mask with optional input", function() {
expect( 1 );
var input = $( "#mask1" ).val("1234").mask({
mask: "(999) 999-9999?x9999",
});

equal( input.val(), "(123) 4__-____", "Initial value" );
});

test( "mask option parser", 1, function() { test( "mask option parser", 1, function() {
var defs = { var defs = {
hh: function( value ) { hh: function( value ) {
Expand Down

0 comments on commit 3f23f5e

Please sign in to comment.