Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error importing with typescript from jest unit test #30

Open
mblandfo opened this issue Nov 2, 2020 · 3 comments
Open

Error importing with typescript from jest unit test #30

mblandfo opened this issue Nov 2, 2020 · 3 comments

Comments

@mblandfo
Copy link

mblandfo commented Nov 2, 2020

I am seeing this error (#13 ) when running a jest test against a .vue file that imports 'vuex-composition-helpers'

"vuex-composition-helpers": "1.0.21"

I have tried the mentioned updates to vue.config.js and tsconfig.json from https://github.com/greenpress/vuex-composition-helpers#transpiling

@codejockie
Copy link

codejockie commented Jan 14, 2021

@mblandfo A fix you could apply to get your tests working again is to mock out the library. In Jest I will do this:

jest.mock('vuex-composition-helpers', () => ({
    useState: jest.fn(() => {
        return {
             /* values in your store */
        };
    }),
    // Other functions here
}));

@pgarciaegido
Copy link

A quick workaround would be to slightly modify the way you import the library, going directly to the dist folder:

import { createNamespacedHelpers } from 'vuex-composition-helpers/dist';

@rowanfuchs
Copy link

@mblandfo A fix you could apply to get your tests working again is to mock out the library. In Jest I will do this:

jest.mock('vuex-composition-helpers', () => ({
    useState: jest.fn(() => {
        return {
             /* values in your store */
        };
    }),
    // Other functions here
}));

I've tried this but then the store isn't available within the test, how would you test the component that uses a getter that retrieves the mocked state for example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants