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 6685123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:01:20+00:00 2026-05-26T05:01:20+00:00

I am trying to make a test of a function that does some pretty

  • 0

I am trying to make a test of a function that does some pretty simple validation for a form.
However I cannot figure out how to use qunit without passing vars to the function.
here is an example of what I am talking about

  function validateForm(){
        var name = $('#name').val();
        var submit = true;
        //do some validation
        //if submit true
        form.submit();
   }

all the example of qunit I see in the docs do something like this

   ok(validateForm('hello'),'Hello is a valid name');

should I just modify my function or is there a way to work with such a setup.

//EDIT

The option I have chosen to pursue right now is setting up another function above the current one that simply parses the form inputs and then sends them as vars to the validateForm() function

  • 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-05-26T05:01:21+00:00Added an answer on May 26, 2026 at 5:01 am

    What I ended up doing was modifying the function in a way that allowed me to pass the vars in the test.

    before the code would do something like this

           function validateForm(){
                   var value1 = $('#someinput').val();
                   //Do some validation based on these vars
                   $('#someform').submit();
            }
    

    Now When the submit button is pressed it goes to another function that parses the args out for me also added a ‘test’ arg so the form is not being submitted during the tests.

         function parseFormArgs(){
                 var value1 = $('#someinput').val();
                 var value2 = $('#otherinput').val();
                 var test = false;
    
                 validateForm(value1,value2,test);
         }
    
         function validateForm(value1,value2,test){
                   var submit = true;
                   //Do some validation
                   if( test != true && submit ){
                       $('#someform').submit();
                   }
    
                  return submit;
        }
    

    Then my qunit looks something like this

          var testFn = true;
          test('validateForm()', function(){
               equals(validateForm('ExampleVal1','ExampleVal2',testFn), false, 'Such and Such Values should not validate');
               ...
               ...
           });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to make a boolean test so that if one of the
I have been trying to test my application to make sure that all the
Trying to make a custom :confirm message for a rails form that returns data
I've been trying to make a little simple game just to test my logics,
I am trying to make a form with some dynamic behavior. Specifically, I have
I'm trying to figure out how to make an opposite of a jquery ui
I'm trying to create a function that will check to make sure all the
I am trying to make a Test Webservice and throw a SoapException. But when
I'm trying to test an application and I need to make an valid IP
Trying to make a make generic select control that I can dynamically add elements

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.