Question: I have a function in my component inside of `setup()`:

```js
export default defineComponent({
  setup() {
    const handleResume = async () => {
      msg.value = {}
      try {
      } catch (err) {
      }
    }
    return { handleResume }
  }
})

```

Now in my test, I want to create a spy function like this:

```js
import App from '@/views/Frame'
jest.spyOn(App, 'handleResume')

```

But I am getting this error:

```
Cannot spy the handleResume property because it is not a function; undefined given instead

```

Answer: 
This requires Vue [3.2.31](https://github.com/vuejs/core/releases/tag/v3.2.31) (released yesterday), which adds [support for mocking `Proxy` methods](https://github.com/vuejs/core/pull/4216), enabling spies on the [`wrapper.vm` from `@vue/test-utils`](https://vue-test-utils.vuejs.org/api/wrapper/#vm).

You can expose methods (or other data) from `setup()` with the [`expose` property from the `context` argument](https://vuejs.org/api/composition-api-setup.html#exposing-public-properties). For example, this component exposes `handleResume` only in tests:

```html
<!-- MyComponent.vue -->
<script>
import { defineComponent } from 'vue'

export default defineComponent({

  setup(props, { expose }) {
    const handleResume = async () => true

    if (process.env.NODE_ENV === 'test') {

      expose({ handleResume })
    }

    return { handleResume }
  }
})
</script>

<template>
  <button @click="handleResume">Click</button>
</template>

```

If you have `<script setup>` instead, use the [`defineExpose()` macro](https://vuejs.org/api/sfc-script-setup.html#defineexpose):

```html
<!-- MyComponent.vue -->
<script setup>
const handleResume = async () => true

if (process.env.NODE_ENV === 'test') {

  defineExpose({ handleResume })
}
</script>

```

Then spy on the exposed `handleResume` from the `wrapper.vm`:

```js
// MyComponent.spec.js
import { shallowMount } from '@vue/test-utils'
import MyComponent from '@/components/MyComponent.vue'

describe('MyComponent', () => {
  it('handles resume', async () => {
    const wrapper = shallowMount(MyComponent)

    const handleResume = jest.spyOn(wrapper.vm, 'handleResume')

    await wrapper.find('button').trigger('click')
    expect(handleResume).toHaveBeenCalled()
  })
})

```

[demo](https://stackblitz.com/edit/vue-spy-on-setup-methods?file=tests%2Funit%2FMyComponent.spec.js)
you have to switch setup from object to function which return object. So your setup should looks like this:

```js
setup() {
  const handleResume = async () => {
        msg.value = {}
        try {

        } catch (err) {

        }
      }

  return { handleResume }
}

```

After this you have two options, you can use @vue/test-utils, mount component as wrapper in test file and you should get access to your function by wrapper.vm.handleResume. Other solution, you can export your setup to composable and import composable into test instead of mounting component.