'Nuxt Jest Testing axios

I am using nuxt with jest to test my axios isit working but i keep having this error which i not sure what happen.

AppNotifications.vue

<template>
    <div>
        <li v-for="notification in notifications" :key="notification.id">
            {{ notification.body }}
        </li>
    </div>
</template>
<script>
    export default {
        data() {
            return {
                notifications: []
            }
        },

        methods: {
            async takeNotifications() {
                let response = await this.$axios.$get('/notifications.json')

                console.log(response)
                // this.notifications = response.data.data
            }
        },

        mounted() {
            this.takeNotifications()
        }

    }
</script>

AppNotifications.spec.js

import {
    mount
}
from '@vue/test-utils'
import AppNotifications from '@/components/AppNotifications.vue'
import axios from 'axios'

jest.mock('axios', () => {
    return {
        $get: jest.fn(() => Promise.resolve({
            name: 'alex'
        }))
    }
})

describe('AppNotifications', () => {
    it('renders a list of notifications', () => {
        let wrapper = mount(AppNotifications)
    })
})

Error call out test:

Determining test suites to run...[warn] `mode` option is deprecated. Please use `ssr: true` for universal mode or `ssr: false` for spa mode and remove `mode` from `nuxt.config`

 RUNS  __tests__/AppNotifications.spec.js
node:internal/process/promises:246
          triggerUncaughtException(err, true /* fromPromise */);
          ^

[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "TypeError: Cannot read properties of undefined (reading '$get')".] {
  code: 'ERR_UNHANDLED_REJECTION'
}

what is wrong with this test ? is my first time doing test on jest.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source