mercredi 18 juillet 2018

How to access global functions in a SFC for a vue test

How would I test my SFC if it depends on some methods that are included in the main.js e.g.

main.js

Vue.mixin(
        methods: {
            axiosAjax,
        }
    }
)

/* eslint-disable no-new */
new Vue(
    {
        el: "#app",
        router,
        store,
        components: { App },
        template: "<App/>",
    }
)

It can't find axiosAjax

How I'm trying to test

import { mount } from "@vue/test-utils"
import AccountMap from "@/components/Account/AccountMap/AccountMap"

describe("AccountMap.vue", () =>
{
    it(
        "does something",
        () =>
        {
            delete AccountMap.mounted
            let mounted = mount(AccountMap)
            console.log(mounted.axiosAjax)
            expect(mounted.contains("div")).toBe(true)
        }
    )
})

There's no axiosAjax, but I can access it when I run app in a website.

Aucun commentaire:

Enregistrer un commentaire