Vuex-persistedstate: Invalid storage instance given with jest runner

Created on 14 Jan 2018  路  3Comments  路  Source: robinvdvleuten/vuex-persistedstate


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?

Most helpful comment

I solved this by mocking the localStorage using jest-localstorage-mock for anyone facing this issue.

All 3 comments

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.

Was this page helpful?
0 / 5 - 0 ratings