title: Cannot spyOn on a primitive value; undefined given . Vue JS, Jest, Utils
body: <p>I try to use spyOn to spy the functions and it's implementation. However, i got this error. &quot;Cannot spyOn on a primitive value; undefined given&quot;.</p>
  <p>I already read the documentation of jest.spyOn in <a href="https://jestjs.io/docs/en/jest-object" rel="noreferrer">https://jestjs.io/docs/en/jest-object</a> . But it keeps showing the same errror... is there anything that i should add and improve?</p>
  <p>below is the code</p>
  <pre><code>&lt;template&gt;
    &lt;div&gt;
      &lt;form @submit.prevent=&quot;onSubmit(inputValue)&quot;&gt;
        &lt;input type=&quot;text&quot; v-model=&quot;inputValue&quot;&gt;
        &lt;span class=&quot;reversed&quot;&gt;{{ reversedInput }}&lt;/span&gt;
      &lt;/form&gt;
    &lt;/div&gt;
  &lt;/template&gt;
  
  &lt;script&gt;
  import axios from 'axios';
  
  export default {
    props: ['reversed'],
    data: () =&gt; ({
      inputValue: '',
      results: [],
    }),
    methods: {
      onSubmit(value) {
        const getPromise = axios.get(
          'https://jsonplaceholder.typicode.com/posts?q=' + value,
        );
  
        getPromise.then(results =&gt; {
          this.results = results.data;
        });
  
        return getPromise;
      },
    },
  };
  &lt;/script&gt;
  </code></pre>
  <p>while the test code is</p>
  <pre><code>import axios from 'axios'; // axios here is the mock from above!
  import { shallowMount } from '@vue/test-utils';
  
  
  import Form from '@/components/Form.vue';
  
  describe('Form.test.js', () =&gt; {
    const wrapper;
  
    describe('Testing Submit events', () =&gt; {
      wrapper = shallowMount(Form);
    
      it('calls submit event', () =&gt; {
          const onSubmit = jest.spyOn(Form.prototype, 'onSubmit') // mock function
    
          // updating method with mock function
          wrapper.setMethods({ onSubmit });
    
          //find the button and trigger click event
          wrapper.findAll('form').trigger('submit');
          expect(onSubmit).toBeCalled();
      })
    
  
    });
  
  })
  </code></pre>
  <p>Can you also vrief me what and how to use spyOn to test the method?</p>
  <p>Thank you so much</p>
  <p>Best regards</p>
  <p>Lughni</p>