forked from select2/select2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata-tests.js
More file actions
55 lines (37 loc) · 1.41 KB
/
Copy pathdata-tests.js
File metadata and controls
55 lines (37 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
var $ = require('jquery');
var Utils = require('select2/utils');
module('Utils - GetUniqueElementId');
test('Adds a prefix to the existing ID if one exists', function (assert) {
var $element = $('<select id="existing-id"></select>');
var id = Utils.GetUniqueElementId($element[0]);
assert.notEqual(id, 'existing-id');
assert.notEqual(id.indexOf('existing-id'), -1);
});
test('Generated random ID is not a number', function (assert) {
var $element = $('<select></select>');
var id = Utils.GetUniqueElementId($element[0]);
assert.ok(isNaN(id));
});
module('Utils - RemoveData');
test('The data-select2-id attribute is removed', function (assert) {
var $element = $('<select data-select2-id="test"></select>');
Utils.RemoveData($element[0]);
assert.notEqual(
$element.attr('data-select2-id'),
'test',
'The internal attribute was not removed when the data was cleared'
);
});
test('The internal cache for the element is cleared', function (assert) {
var $element = $('<select data-select2-id="test"></select>');
Utils.__cache.test = {
'foo': 'bar'
};
Utils.RemoveData($element[0]);
assert.equal(Utils.__cache.test, null, 'The cache should now be empty');
});
test('Calling it on an element without data works', function (assert) {
assert.expect(0);
var $element = $('<select></select>');
Utils.RemoveData($element[0]);
});