diff options
author | Scott González <scott.gonzalez@gmail.com> | 2012-04-03 16:47:14 -0400 |
---|---|---|
committer | Scott González <scott.gonzalez@gmail.com> | 2012-04-03 16:47:14 -0400 |
commit | 96f9c84b7b2149c6b93ac226a52065652f218e1e (patch) | |
tree | 9f15376ff3cbf3726de4af4ed45494701b6804c0 /tests/unit/autocomplete | |
parent | 4ade13450e7145100dcce3356eb1449e1a5f7090 (diff) | |
download | jquery-ui-96f9c84b7b2149c6b93ac226a52065652f218e1e.tar.gz jquery-ui-96f9c84b7b2149c6b93ac226a52065652f218e1e.zip |
Autocomplete: Move race condition logic from ajax requests to general response handler. Fixes #8234 - Autocomplete: Automatic race-condition handling for custom sources.
Diffstat (limited to 'tests/unit/autocomplete')
-rw-r--r-- | tests/unit/autocomplete/autocomplete_core.js | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/unit/autocomplete/autocomplete_core.js b/tests/unit/autocomplete/autocomplete_core.js index ef6ea58af..daeea0972 100644 --- a/tests/unit/autocomplete/autocomplete_core.js +++ b/tests/unit/autocomplete/autocomplete_core.js @@ -123,4 +123,33 @@ test( "allow form submit on enter when menu is not active", function() { } })(); +asyncTest( "handle race condition", function() { + expect( 3 ); + var count = 0, + element = $( "#autocomplete" ).autocomplete({ + source: function( request, response ) { + count++; + if ( request.term.length === 1 ) { + equal( count, 1, "request with 1 character is first" ); + setTimeout(function() { + response([ "one" ]); + setTimeout( checkResults, 1 ); + }, 1 ); + return; + } + equal( count, 2, "request with 2 characters is second" ); + response([ "two" ]); + } + }); + + element.autocomplete( "search", "a" ); + element.autocomplete( "search", "ab" ); + + function checkResults() { + equal( element.autocomplete( "widget" ).find( ".ui-menu-item" ).text(), "two", + "correct results displayed" ); + start(); + } +}); + }( jQuery ) ); |