diff options
author | Rob Loach <robloach@gmail.com> | 2014-10-05 20:33:32 -0400 |
---|---|---|
committer | Rob Loach <robloach@gmail.com> | 2014-10-05 20:33:32 -0400 |
commit | cd0cedd62e15aad594fec8a958e3bf03580da119 (patch) | |
tree | cb698a7f4e22d02f75d1c69d0d359dd6d2dd8268 /test | |
parent | b9d4116966d6c4f61a421061e3bf4da28bfb0764 (diff) | |
download | jquery-once-cd0cedd62e15aad594fec8a958e3bf03580da119.zip jquery-once-cd0cedd62e15aad594fec8a958e3bf03580da119.tar.gz jquery-once-cd0cedd62e15aad594fec8a958e3bf03580da119.tar.bz2 |
Add the findOnce() function
Diffstat (limited to 'test')
-rw-r--r-- | test/index.html | 5 | ||||
-rw-r--r-- | test/test.js | 20 |
2 files changed, 25 insertions, 0 deletions
diff --git a/test/index.html b/test/index.html index 887b696..038db22 100644 --- a/test/index.html +++ b/test/index.html @@ -24,6 +24,11 @@ <p>This is <span>Test 4</span>.</p> </div> + <div id="test5"> + <p>This is <span>Test 5</span>.</p> + <p>This is <span>Test 5 #2</span>.</p> + </div> + </div> <script src="http://code.jquery.com/jquery-2.1.1.js"></script> diff --git a/test/test.js b/test/test.js index a0c3d58..6e6353f 100644 --- a/test/test.js +++ b/test/test.js @@ -59,3 +59,23 @@ test("Remove the value from attribute correctly", function() { hasData = $('#test4 span').data('jquery-once-test4'); ok(!hasData, 'The value is properly removed when called removeOnce().'); }); + +test("Finding elements correctly through findOnce()", function() { + // Create one once() call. + $('#test5 span').once('test5', function() { + // Do nothing. + }); + + // Find the once'd element through the callback. + var elements = $('span').findOnce('test5', function() { + var hasData = $(this).data('jquery-once-test5'); + ok(hasData, 'Finding the correct span element after once() through callback.'); + }); + + // Find the once'd element without the callback. + elements = $('span').findOnce('test5'); + elements.each(function() { + var hasData = $(this).data('jquery-once-test5'); + ok(hasData, 'Finding the correct span element after once().'); + }); +}); |