title: ReactJS Testing a helper method using jest spyOn
body: <p>So I have the following helper method -</p>
  
  <pre><code>import { FormFieldError, FormValidationRules } from "../../../types/form.type";
  
  const isString = (value: any, fieldId: string, fieldName: string): FormFieldError | null =&gt; {
    // Check if field value is of type string
    if (typeof value !== 'string') {
      return {
        fieldId,
        message: `${fieldName} must be string.`
      };
    }
  
    return null;
  }
  
  const validateField = (value: any, rules: FormValidationRules[], fieldId: string, fieldName: string): FormFieldError | null =&gt; {
    let error: FormFieldError | null = null;
  
    // Let's go through each of the rules
    for (const rule of rules) {
      // Let's check against mandatory value
      if (error === null &amp;&amp; rule === 'string') {
        error = isString(value, fieldId, fieldName);
      } else if (error !== null) {
        break;
      }
    }
  
    // Let's return the error
    return error;
  }
  
  export default validateField;
  </code></pre>
  
  <p>Now I want to write a test that tests if <code>isString</code> method is called using spyOn. If I do something like this - </p>
  
  <pre><code>import validateField from './FormValidationRules';
  
  describe('Test if necessary functions are called', () =&gt; {
    it('Should call isString method with according parameters', () =&gt; {
      const isStringSpy = spyOn(validateField, 'isString');
  
      validateField(null, ['string'], 'name', 'Name');
  
      expect(isStringSpy).toHaveBeenCalled();
    });
  });
  </code></pre>
  
  <p>It complains about <code>Argument of type "isString" is not assignable to parameter of type 'never'</code>.</p>
  
  <p>If I try to add the method isString within the function validateField, it still complains about the same issue.</p>
  
  <p>Any suggestions would be welcome.</p>