title: How to unit test javascript function which takes in a parameter using jasmine or mocha
body: <p>I have a simple question. How do I unit test a function which is dependent on a parameter? Like say for example: </p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>function a(param) {
     if(param &gt; 0) 
        return param+value;
     else
        return param;
  }
  </code></pre>
  
  <p>How do I unit test function a without having param? I hear this I use mocks or spies in jasmine. Can someone show me an example, I am really confused. Thank you all in advance. </p>
  
  <p><strong>Edit:</strong></p>
  
  <p>Thank you for such a conprehensive answer David. I really appreciate it. Here is more information about my question. </p>
  
  <p>This is in fact my true question, I have a file</p>
  
  <p><strong><em>snap-fed.js</em></strong> :</p>
  
  <pre><code>//Code here...
  </code></pre>
  
  <p>Which I would like to unit test comprehensively as you showed me. But I am unsure as to how to do this using jasmine or mocha. </p>
  
  <p>Like how could I test any of the methods of the snap object? How could I unit test snap.eligibility or snap.isSnapResourceEligibile? I have been stuck on this issue for about 2 days, I really don't understand. </p>
  
  <p>They all take in a parameter info which provides info about the object being worked on by the methods. </p>
  
  <p>This was my true question but I did not know how to ask it. </p>
  
  <p><strong>Edit 2:</strong> </p>
  
  <p>Based on David's template I made this, but it doesn't even run...</p>
  
  <p><strong><em>snap-fed.spec.js</em></strong> : </p>
  
  <pre><code>describe("snap-fed", function() { 
  
    describe("Properties", function() { 
  
      it("should exist", function() {
        expect(Allowance).not.toBeUndefined(); 
        expect(AllowanceAdditional).not.toBeUndefined();
        expect(MaxAllowanceHouseholdSize).not.toBeUndefined();
      }); 
  
      it("should contain correct values", function() {
          expect(Allowance).toEqual([189, 347, 497, 632, 750, 900, 995, 1137]);
          expect(AllowanceAdditional).toBe(142);
          expect(MaxAllowanceHouseholdSize).toBe(Allowance.length);
      }); 
    });
  
    describe("Functions", functions(){
  
      it("should return the expected result", function() {
        expect(snap.isSnapResourceEligible(info)).toBeTruthy();
      });
  
      //Put more test cases for the various methods of snap
  
    });
  
  }); 
  </code></pre>