Merge pull request #218 from joshjb84/master

Fix to naming in inputmask.js and added some inputmask tests
This commit is contained in:
Arnold Daniels
2014-04-06 22:10:54 +02:00
2 changed files with 65 additions and 4 deletions

View File

@@ -32,7 +32,7 @@
if (isAndroid) return // No support because caret positioning doesn't work on Android
this.$element = $(element)
this.options = $.extend({}, Inputmask.DEFAULS, options)
this.options = $.extend({}, Inputmask.DEFAULTS, options)
this.mask = String(this.options.mask)
this.init()
@@ -41,7 +41,7 @@
this.checkVal() //Perform initial check for existing values
}
Inputmask.DEFAULS = {
Inputmask.DEFAULTS = {
mask: "",
placeholder: "_",
definitions: {

View File

@@ -1,6 +1,13 @@
$(function () {
module('inputmask')
var $body;
module('inputmask', {
setup : function() {
$body = $(document.body);
$body.removeData('inputmask');
}
})
test('should provide no conflict', function () {
var inputmask = $.fn.inputmask.noConflict()
@@ -15,6 +22,60 @@ $(function () {
test('should return element', function () {
ok($(document.body).inputmask()[0] == document.body, 'document.body returned')
})
test('should use default mask', function() {
var expected = ""
$.fn.inputmask.Constructor.DEFAULTS.mask = expected
$body.inputmask()
equal(expected, $body.data('inputmask').options.mask)
})
test('should use default placeholder', function() {
var expected = "_"
$.fn.inputmask.Constructor.DEFAULTS.placeholder = expected
$body.inputmask()
equal(expected, $body.data('inputmask').options.placeholder)
})
test('should use default definitions', function() {
var expected = {
'9': "[0-9]",
'a': "[A-Za-z]"
}
$.fn.inputmask.Constructor.DEFAULTS.definitions = expected
$body.inputmask()
deepEqual(expected, $body.data('inputmask').options.definitions)
})
test('should override mask when options.mask provided', function() {
var expected = '99-99';
$body.inputmask({ mask: expected})
equal(expected, $body.data('inputmask').options.mask)
})
test('should override placeholder when options.placeholder provided', function() {
var expected = '-';
$body.inputmask({ placeholder: expected})
equal(expected, $body.data('inputmask').options.placeholder)
})
test('should override definitions when options.definitions provided', function() {
var expected = {
'9': "[0-9]",
'a': "[A-Za-z]"
}
$body.inputmask({definitions: expected})
deepEqual(expected, $body.data('inputmask').options.definitions)
})
// TODO: add inputmask tests
})