Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8434151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:34:46+00:00 2026-06-10T06:34:46+00:00

In my QUnit test I want to mock out autocomplete method (jQuery UI), but

  • 0

In my QUnit test I want to mock out autocomplete method (jQuery UI), but every time I’m runing test like:

test("Create_PassedContainer_RunsAutocompleteOnMatchingElement",function(){
    var $matchingInput = $('<input data-autocomplete-url="some"/>');
    var $dom = $('<div><input/></div>');
    $dom.append($matchingInput);
    var autocompleteWasCalled = false;
    $matchingInput.autocomplete = function(){ autocompleteWasCalled = true; };

    new Autocomplete($dom);

    ok(autocompleteWasCalled,"Should call autocomplete.");
});

I’m getting result:

TypeError: Object [object Object] has no method 'autocomplete'.

Code under test:

function Autocomplete($container) {
    var $self = this;

    this.Initialize = function($container) {
        $self.$container = $container;
        $self.$text = $('*[data-autocomplete-url]', $container);
        $self.$value = $('input[type="hidden"]', $container);

        $self.$text.autocomplete();
    };

    $self.Initialize($container);
};

Anything would be helpful.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T06:34:48+00:00Added an answer on June 10, 2026 at 6:34 am

    Autocomplete is a plugin, try this:

    var oldAutocomplete = $.fn.extend(true, {}, $.autocomplete);
    $.autocomplete = function(){
        autocompleteWasCalled = true;
    }
    
    /// Other code...
    
    $.fn.autocomplete = oldAutocomplete;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using QUnit and JQuery and want to test user interface of my
I'm trying to get a simple test going with QUnit but for some reason
I am trying out qunit while writing a jQuery plugin and I was wondering
I am trying to use Qunit to test some code, but I have some
Use case is this: I want to unit test (in browser, QUnit or something
I want to use JsTestDriver to drive my QUnit tests, but I'm confused about
I would like to be able to issue the command rake test:qunit and to
I am just getting started with JS Unit Testing and am trying out qUnit.
I feel ridiculous having to ask this, but I can't tell if maven-qunit-plugin is
I'm starting to write some unit test for my javascript code using qunit and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.