0

I try to run a test with vue-test-utils, including a component that has a mixin included, which has a function using split() on a string. The test looks like this:

describe('adminExample.vue Test', () => {
    const wrapper = shallowMount(adminExample, {
        global: {
            mixins: [globalHelpers, authGatewayForElements, storeService],
            plugins: [store]
        }
    })
    it('renders component and is named properly', () => {
        // check the name of the component
        expect(wrapper.vm.$options.name).toMatch('adminExample')
    })
})

adminExample.vue doesn't give any error, so I don't include it here, bit it uses a mixin.

The included mixin, called authGatewayForElements, has a function called decryptToken() and simply decrypt a jwt to get some info. The parameter userToken is declared within data of this mixin. The function looks like this:

decryptToken() {
            let base64Split = this.userToken.split('.')[1];
            let base64 = base64Split.replace(/-/g, '+').replace(/_/g, '/');
            let jsonPayload = decodeURIComponent(atob(base64).split('').map(function(c) {
                return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
            }).join(''));
            return JSON.parse(jsonPayload);
        },

Running the test giving me the error TypeError: this.userToken.split is not a function . I´m new to testing with vue-test-utils and maybe or definitely missing something that needs to beincluded in the wrapper, as I expected functions like split() don't need to be included additionally.


EDIT: I get this error on multiple functions, like find(), so I'm pretty sure I just do something wrong. Thanks in advance to anybody pointing that out.

2
  • What version of Vue are you using? Can you share a link to a reproduction of the problem? Commented May 12, 2022 at 23:47
  • @tony19 I'm using vue 3.1.4 with vue cli 2.9.6 and vue/cli-plugin-unit-jest 5.0.4. There are a lot of other dependencies so I can't really recreate the problem in a sandbox. This looks like a general error for something that's been missing. Do you have any idea? Commented May 16, 2022 at 7:09

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.