Skip to content

Commit

Permalink
Fixed unit test for inputmask
Browse files Browse the repository at this point in the history
  • Loading branch information
jasny committed May 6, 2014
1 parent 1dfd002 commit c12018a
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions js/tests/unit/inputmask.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
$(function () {

var $body;
var $input;

module('inputmask', {
setup : function() {
$body = $(document.body);
$body.removeData('inputmask');
$input = $('<input type="text">').appendTo(document.body);
$input.removeData('inputmask');
}
})

Expand All @@ -16,66 +16,66 @@ $(function () {
})

test('should be defined on jquery object', function () {
ok($(document.body).inputmask, 'inputmask method is defined')
ok($input.inputmask, 'inputmask method is defined')
})

test('should return element', function () {
ok($(document.body).inputmask()[0] == document.body, 'document.body returned')
ok($input.inputmask()[0] == $input[0], 'input returned')
})

test('should use default mask', function() {
var expected = ""
$.fn.inputmask.Constructor.DEFAULTS.mask = expected

$body.inputmask()
$input.inputmask()

equal(expected, $body.data('inputmask').options.mask)
equal(expected, $input.data('bs.inputmask').options.mask)
})

test('should use default placeholder', function() {
var expected = "_"
$.fn.inputmask.Constructor.DEFAULTS.placeholder = expected

$body.inputmask()
$input.inputmask()

equal(expected, $body.data('inputmask').options.placeholder)
equal(expected, $input.data('bs.inputmask').options.placeholder)
})

test('should use default definitions', function() {
var expected = {
'9': "[0-9]",
'a': "[A-Za-z]"
'0': "[0-9]",
'A': "[A-Za-z]"
}
$.fn.inputmask.Constructor.DEFAULTS.definitions = expected

$body.inputmask()
$input.inputmask()

deepEqual(expected, $body.data('inputmask').options.definitions)
deepEqual(expected, $input.data('bs.inputmask').options.definitions)
})

test('should override mask when options.mask provided', function() {
var expected = '99-99';
$body.inputmask({ mask: expected})
$input.inputmask({ mask: expected})

equal(expected, $body.data('inputmask').options.mask)
equal(expected, $input.data('bs.inputmask').options.mask)
})

test('should override placeholder when options.placeholder provided', function() {
var expected = '-';
$body.inputmask({ placeholder: expected})
$input.inputmask({ placeholder: expected})

equal(expected, $body.data('inputmask').options.placeholder)
equal(expected, $input.data('bs.inputmask').options.placeholder)
})

test('should override definitions when options.definitions provided', function() {
var expected = {
'9': "[0-9]",
'a': "[A-Za-z]"
'0': "[0-9]",
'A': "[A-Za-z]"
}

$body.inputmask({definitions: expected})
$input.inputmask({definitions: expected})

deepEqual(expected, $body.data('inputmask').options.definitions)
deepEqual(expected, $input.data('bs.inputmask').options.definitions)
})
// TODO: add inputmask tests
})

0 comments on commit c12018a

Please sign in to comment.