Do you want to request a feature or report a bug?
Report a bug
What is the current behavior?
when importing my component into my test file i get the test failing with jest runner with the error Invalid storage instance given
Invalid storage instance given
59 | },
60 | strict: debug,
> 61 | plugins: [createPersistedState({
62 | key: 'something',
63 | paths: ['auth'],
64 | })],
If the current behavior is a bug, please provide the steps to reproduce.
i just import my component that is using the store and the store is using vuex-persistedstate this is producing the error
import { createLocalVue, mount } from 'vue-test-utils';
import Header from '@/components/Header';
import VueRouter from 'vue-router';
const localVue = createLocalVue();
localVue.use(VueRouter);
const routes = [];
const router = new VueRouter({
routes,
});
const wrapper = mount(Header, {
localVue,
router,
});
test('Header renders', () => {
expect(wrapper.html()).toContain('<div class="home"><img src="../assets/img/[email protected]" alt="logo"><h1 style="color: #48576a;"></h1></div>');
});
What is the expected behavior?
tests runs without error
If this is a feature request, what is motivation or use case for changing the behavior?
You are probably trying to run your test with a localstorage instance. This instance is unavailable in your test environment, so I suggest you'll use a package like dom-storage. See customizing storage for more information.
I solved this by mocking the localStorage using jest-localstorage-mock for anyone facing this issue.
If you dont want to mock you could also check against process.env.NODE_ENV to only add the plugin if its not test.
Most helpful comment
I solved this by mocking the localStorage using jest-localstorage-mock for anyone facing this issue.