Skip to content
This repository was archived by the owner on Oct 8, 2021. It is now read-only.

Commit 8eab5fd

Browse files
author
Gabriel Schulhof
committed
Textinput: Test _destroy() and (lack of) call to _destroyClear()
1 parent 151ab0b commit 8eab5fd

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

tests/unit/textinput/index.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<script src="../../../external/requirejs/require.js"></script>
99
<script src="../../../js/requirejs.config.js"></script>
1010
<script src="../../../js/jquery.tag.inserter.js"></script>
11+
<script src="../../jquery.setNameSpace.js"></script>
1112
<script src="../../../external/qunit/qunit.js"></script>
1213
<script src="../../../tests/jquery.testHelper.js"></script>
1314
<script>
@@ -58,14 +59,17 @@
5859

5960
<input type="text" id="text-input">
6061

61-
<input type="text" data-clear-btn="true" id="text-input-clear-btn">
62+
<input type="text" data-nstest-clear-btn="true" id="text-input-clear-btn">
6263

63-
<textarea data-clear-btn="true" id="textarea-clear-btn"></textarea>
64+
<textarea data-nstest-clear-btn="true" id="textarea-clear-btn"></textarea>
6465

6566
<input id="test-clear-btn-option"></input>
6667

6768
<input type="text" id="focus-class-test-for-input"></input>
6869
<textarea id="focus-class-test-for-textarea"></textarea>
70+
<div id="destroy-test-container">
71+
<input type="text" id="destroy-test" data-nstest-role="none"></input>
72+
</div>
6973
</div>
7074
</body>
7175
</html>

tests/unit/textinput/textinput_core.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,35 @@
149149
"turning off clearBtn removes wrapper class 'ui-input-has-clear'" );
150150
});
151151

152+
( function() {
153+
154+
var originalDestroyClear = $.mobile.textinput.prototype._destroyClear,
155+
destroyClearCalled = false;
156+
157+
module( "Textinput destroy", {
158+
setup: function() {
159+
$.mobile.textinput.prototype._destroyClear = function() {
160+
destroyClearCalled = true;
161+
return originalDestroyClear.apply( this, arguments );
162+
}
163+
},
164+
teardown: function() {
165+
$.mobile.textinput.prototype._destroyClear = originalDestroyClear;
166+
}
167+
});
168+
169+
test( "textinput is destroyed correctly", function() {
170+
var originalDOM = $( "#destroy-test-container" ).clone(),
171+
entry = $( "#destroy-test" );
172+
173+
entry.textinput().textinput( "destroy" );
174+
175+
deepEqual( $.testHelper.domEqual( originalDOM, $( "#destroy-test-container" ) ), true,
176+
"Original DOM is restored after textinput destruction" );
177+
178+
deepEqual( destroyClearCalled, false, "_destroyClear() was not called" );
179+
});
180+
181+
})();
182+
152183
})(jQuery);

0 commit comments

Comments
 (0)