vuex-composition-helpers
vuex-composition-helpers copied to clipboard
Error importing with typescript from jest unit test
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
@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
}));
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';
@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.