Giter Site home page Giter Site logo

vuex-mock-store's Introduction

vuex-mock-store Build Status npm package coverage thanks

Simple and straightforward mock for Vuex v3.x and v4.x (Vue 2 and 3)

Automatically creates spies on commit and dispatch so you can focus on testing your component without executing your store code.

Help me keep working on Open Source in a sustainable way 🚀. Help me with as little as $1 a month, sponsor me on Github.

Silver Sponsors

Vue Mastery logo

Vuetify logo

Bronze Sponsors

Storyblok logo


Installation

npm install -D vuex-mock-store
# with yarn
yarn add -D vuex-mock-store

Usage

ℹ️: All examples use Jest API. See below to use a different mock library.

Usage with vue-test-utils:

Given a component MyComponent.vue:

<template>
  <div>
    <p class="count">{{ count }}</p>
    <p class="doubleCount">{{ doubleCount }}</p>
    <button class="increment" @click="increment">+</button>
    <button class="decrement" @click="decrement">-</button>
    <hr />
    <button class="save" @click="save({ count })">Save</button>
  </div>
</template>

<script>
import { mapState, mapGetters, mapActions, mapMutations } from 'vuex'

export default {
  computed: {
    ...mapState(['count']),
    ...mapGetters(['doubleCount']),
  },
  methods: {
    ...mapMutations(['increment', 'decrement']),
    ...mapActions(['save']),
  },
}
</script>

You can test interactions without relying on the behaviour of your actions and mutations:

import { Store } from 'vuex-mock-store'
import { mount } from '@vue/test-utils'
import MyComponent from '@/components/MyComponent.vue'

// create the Store mock
const store = new Store({
  state: { count: 0 },
  getters: { doubleCount: 0 },
})
// add other mocks here so they are accessible in every component
const mocks = {
  global: { $store: store },
  // for Vue 2.x: just { $store: store } without global
}

// reset spies, initial state and getters
afterEach(() => store.reset())

describe('MyComponent.vue', () => {
  let wrapper
  beforeEach(() => {
    wrapper = mount(MyComponent, { mocks })
  })

  it('calls increment', () => {
    wrapper.find('button.increment').trigger('click')
    expect(store.commit).toHaveBeenCalledOnce()
    expect(store.commit).toHaveBeenCalledWith('increment')
  })

  it('dispatch save with count', () => {
    wrapper.find('button.save').trigger('click')
    expect(store.dispatch).toHaveBeenCalledOnce()
    expect(store.dispatch).toHaveBeenCalledWith('save', { count: 0 })
  })
})

⚠️ The mocked dispatch method returns undefined instead of a Promise. If you rely on this, you will have to call the appropriate function to make the dispatch spy return a Promise:

store.dispatch.mockReturnValue(Promise.resolve(42))

If you are using Jest, you can check the documentation here

Initial state and getters

You can provide a getters, and state object to mock them:

const store = new Store({
  getters: {
    name: 'Eduardo',
  },
  state: {
    counter: 0,
  },
})

Modules

State

To mock module's state, provide a nested object in state with the same name of the module. As if you were writing the state yourself:

new Store({
  state: {
    value: 'from root',
    moduleA: {
      value: 'from A',
      moduleC: {
        value: 'from A/C',
      },
    },
    moduleB: {
      value: 'from B',
    },
  },
})

That will cover the following calls:

import { mapState } from 'vuex'

mapState(['value']) // from root
mapState('moduleA', ['value']) // from A
mapState('moduleB', ['value']) // from B
mapState('moduleA/moduleC', ['value']) // from C

When testing state, it doesn't change anything for the module to be namespaced or not

Getters

To mock module's getters, provide the correct name based on whether the module is namespaced or not. Given the following modules:

const moduleA = {
  namespaced: true,

  getters: {
    getter: () => 'from A',
  },

  // nested modules
  modules: {
    moduleC: {
      namespaced: true,
      getter: () => 'from A/C',
    },
    moduleD: {
      // not namespaced!
      getter: () => 'from A/D',
    },
  },
}

const moduleB = {
  // not namespaced
  getters: {
    getter: () => 'from B',
  },
}

new Vuex.Store({ modules: { moduleA, moduleC } })

We need to use the following getters:

new Store({
  getters: {
    getter: 'from root',
    'moduleA/getter': 'from A',
    'moduleA/moduleC/getter': 'from A/C',
    'moduleA/getter': 'from A/D', // moduleD isn't namespaced
    'moduleB/getter': 'from B',
  },
})

Actions/Mutations

As with getters, testing actions and mutations depends whether your modules are namespaced or not. If they are namespaced, make sure to provide the full action/mutation name:

// namespaced module
expect(store.commit).toHaveBeenCalledWith('moduleA/setValue')
expect(store.dispatch).toHaveBeenCalledWith('moduleA/postValue')
// non-namespaced, but could be inside of a module
expect(store.commit).toHaveBeenCalledWith('setValue')
expect(store.dispatch).toHaveBeenCalledWith('postValue')

Refer to the module example below using getters for a more detailed example, even though it is using only getters, it's exactly the same for actions and mutations

Mutating state, providing custom getters

You can modify the state and getters directly for any test. Calling store.reset() will reset them to the initial values provided.

API

Store class

constructor(options)

  • options
    • state: initial state object, default: {}
    • getters: getters object, default: {}
    • spy: interface to create spies. details below

state

Store state. You can directly modify it to change state:

store.state.name = 'Jeff'

getters

Store getters. You can directly modify it to change a value:

store.getters.upperCaseName = 'JEFF'

ℹ️ Why no functions?: if you provide a function to a getter, you're reimplementing it. During a test, you know the value, you should be able to provide it directly and be completely sure about the value that will be used in the component you are testing.

reset

Reset commit and dispatch spies and restore getters and state to their initial values

Providing custom spies

By default, the Store will call jest.fn() to create the spies. This will throw an error if you are using mocha or any other test framework that isn't Jest. In that situation, you will have to provide an interface to create spies. This is the default interface that uses jest.fn():

new Store({
  spy: {
    create: (handler) => jest.fn(handler),
  },
})

The handler is an optional argument that mocks the implementation of the spy.

If you use Jest, you don't need to do anything. If you are using something else like Sinon, you could provide this interface:

import sinon from 'sinon'

new Store({
  spy: {
    create: (handler) => sinon.spy(handler),
  },
})

commit & dispatch

Spies. Dependent on the testing framework

Related

License

MIT

vuex-mock-store's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar greenkeeper[bot] avatar igeligel avatar luanpotter avatar mtimoustafa avatar posva avatar renovate-bot avatar renovate[bot] avatar ronnievdc avatar sobolevn avatar winniehell avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

vuex-mock-store's Issues

Spies on module dispatch and commit throws TypeError

The spies on store.dispatch and store.commit does not work for modules

mapActions('moduleA', ['save'])
mapMutations('moduleA', ['save'])

When having the following Vue component

<template>
  <button @click="save">Save</button>
</template>
 
<script>
import { mapActions } from 'vuex'
 
export default {
  methods: {
    ...mapActions('moduleA', ['save']),
  },
}
</script>

The test to check if save has been called fails

expect(store.commit).toHaveBeenCalledWith('moduleA/save')

With the following error

TypeError: Cannot read property 'apply' of undefined

Why is namespacing implemented completely differently to Vuex?

So in Vuex the way you set up namespacing is like so:

let store = new Vuex.Store({
    modules: {
          moduleA: {
               getters:{}
          }
    }
})

According to the docs for this repo, it sets up namespaces store in a completely different fashion:

new Store({
  state: {
    value: 'from root',
    moduleA: {
      value: 'from A',
      moduleC: {
        value: 'from A/C',
      },
    },
    moduleB: {
      value: 'from B',
    },
  },
})

This is counter-intuitive and makes it impossible to automatically create a store. I'm still having to manually mock everything if I have to completely rewrite it. So I'm struggling to understand what the point of this library is?

Sorry, not meant to be a rant :) just trying to understand.

Maybe I have the complete wrong end of the stick, but my thinking is that I have a namespaces set of stores already. I'm happy with them as is. I just want them mocked, so I can run tests. I really, really don't want to have to manually map every getter, mutation and state pair in order to achieve a mocked store and I can't imagine what the purpose of this library is if it's not automating that?

Utility to generate the getter object based, bypass other actions and mutations

It would be great to also expose some utilities to test the store itself, for example, when testing an action, you may want to write an integration test and therefore not providing the getters but instead using the actual getters object as well as letting mutations and actions get called by dispatch and commit.
A function that generates a context object by being passed a module or store.
Still need to think about the API so it can handle rootState, rootGetters and others properly, also take care of nested modules naming with namespaced

const context = generateContext({ mutations, actions, getters }) // passing a module or store
myAction(context, parameters)
// test things

Testing the Store a part from a component

With a Vuex store is like below I would like to test the interactions inside the store separate from any component. I tried the test below for the given store.js.

I wanted to give you a short example of what I am attempting to do, but it ended up being long 🤷‍♂️

Thank you!

store.js

import Vue from 'vue';
import Vuex from 'vuex';

import {api} from '@/api';

Vue.use(Vuex);

const state = {
  openPayables: [],
  messages: [],
};

export const getters = {
  openPayables: state => state.openPayables,
  messages: state => state.messages,
};

export const mutations = {
  setOpenPayables: (state, payload) => state.openPayables = payload,
  replacePayableInOpenPayables: (state, payload) => {
    state.openPayables = state.openPayables.map(payable => payable.reference === payload.reference ? payload : payable)
  },
  setMessage: (state, payload) => {
    state.messages.push(payload)
  },
  removeMessage: (state, payload) => {
    state.messages = state.messages.filter(msg => msg.reference !== payload.reference);
  }
};

export const actions = {
   parseAPIResponse: ({commit}, {response, duration, title, successMessage}) => {
    let notification = {
      alert_type: null,
      alert_heading: title,
      alert_message: null,
      flashMessage: duration === 'short',
      longMessage: duration === 'long',
    }
    switch (response.status) {
      case 200:
      case 201:
        notification.alert_type = 'success';
        notification.alert_message = successMessage;
        break;
      case 422:
        notification.alert_type = 'warning';
        notification.alert_message = response.data.messages
        break;
      case 500:
      default:
        notification.alert_type = 'error';
        notification.alert_message = response.data;
        break;
    }
    commit('setMessage', notification);
  },
  addPayable: async({dispatch}, payload) => {
    const response = await api.addAccountingPayable(payload)
    dispatch('parseAPIResponse', {
      response, duration: 'short', title: 'Payable', successMessage:'Payable has been added!'
    });
    dispatch('getOpenPayables');
  },
  getOpenPayables: async({commit, state}) => {
    const response = await api.getOpenPayables();
    const openPayables = response.data;
    commit('setOpenPayables', openPayables);
  },
  setMessage: async({commit, state}, payload) => {
    commit('setMessage', payload);
  },
  removeMessage: async({commit, state}, payload) => {
    commit('removeMessage', payload);
  },
};


export const store = new Vuex.Store({
  state,
  getters,
  mutations,
  actions,
});

How would a test the store separate from a component? I would like to test the action addPayable which dispatches another action.

import { Store } from 'vuex-mock-store';
import {actions, mutations, getters} from "@/store";

const store = new Store({
  state: {
    openPayables: [],
    messages: [],
  },
  actions,
  mutations,
  getters,
});

describe('Store', () => {

  afterEach(() => {store.reset()});

  test('adding payable calls the api and sets a notification', done => {

   // WHEN adding a payable
   store.dispatch('addPayable', { "amount": 1.00,});

   // THEN the api response is set as a message for the user
   expect(store.actions.parseAPIResponse).toBeCalledWith({
     response: fakeAddPayableResponse,
     duration: 'short',
     successMessage: 'Payable has been added!',
     title: 'Payable'
   });

   // THEN the message is set for the user
   expect(store.mutations.setMessage).toBeCalledWith({
     alert_type: 'success',
     alert_heading: 'Payable',
     alert_message: 'Payable has been added!',
     flashMessage: true,
     longMessage: false,
   });

   // THEN the list of payables is updated
   expect(store.actions.getOpenPayables).toBeCalled();
  });
});

An in-range update of vue is breaking the build 🚨

The devDependency vue was updated from 2.5.17 to 2.5.18.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

vue is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ci/circleci: build: Your tests failed on CircleCI (Details).

Release Notes for v2.5.18

Includes everything in 2.5.18-beta.0

Bug Fixes

Commits

The new version differs by 164 commits ahead by 164, behind by 4.

  • dadc918 build: release 2.5.18
  • eb81ec2 build: build 2.5.18
  • dfaf9e2 fix(types): type support for advanced async components (#8438)
  • 8a2dbf5 fix(transition-group): fix activeInstance regression
  • 0ed0aad fix: fix keyName checking for space and delete in IE11 (#9150)
  • f077ed1 fix(ssr): fix ssr template publicPath generation
  • 93850f4 chore: fix sponsor link
  • 1b4a8a0 fix(compiler): fix codegen for v-for component inside template
  • 448ba65 fix(types): correct scopedSlot types (#9131)
  • 0d7fb73 chore: update sponsors/backers [ci skip]
  • e8031b4 build: release v2.5.18-beta.0
  • fe194dd build: build v2.5.18-beta.0
  • 3078352 fix(ssr): resolve server directives the same as on client (#9129)
  • aca17b4 ci: add regression test for popular libraries in Vue.js ecosystem (#8608)
  • e4b1b57 fix(ssr): adjust call stack size defer threshold

There are 164 commits in total.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of vue-template-compiler is breaking the build 🚨

The devDependency vue-template-compiler was updated from 2.5.17 to 2.5.18.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

vue-template-compiler is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ci/circleci: build: Your tests failed on CircleCI (Details).

Release Notes for v2.5.18

Includes everything in 2.5.18-beta.0

Bug Fixes

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Dependency Dashboard

This issue provides visibility into Renovate updates and their statuses. Learn more

Awaiting Schedule

These updates are awaiting their schedule. Click on a checkbox to get an update now.

  • chore(deps): update dependency @types/jest to v27.0.2

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.


  • Check this box to trigger a request for Renovate to run again on this repository

An in-range update of vue is breaking the build 🚨

The devDependency vue was updated from 2.5.18 to 2.5.19.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

vue is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ci/circleci: build: Your tests failed on CircleCI (Details).

Release Notes for v2.5.19

Bug Fixes

  • ssr: should not warn for custom directives that do not have ssr implementation 780dac5, closes #9167
  • vdom: remove unnecessary sameVnode condition 0d4b35f, closes #9168

Reverts

  • fix(sfc): avoid deindent when pad option is specified (#7647) 5d721a4, closes #7647
Commits

The new version differs by 6 commits.

  • 628c1b7 build: release 2.5.19
  • c38a81b build: build 2.5.19
  • 0d4b35f fix(vdom): remove unnecessary sameVnode condition
  • 5d721a4 revert: fix(sfc): avoid deindent when pad option is specified (#7647)
  • 780dac5 fix(ssr): should not warn for custom directives that do not have ssr implementation
  • a89384c test(ssr): add basic directives test (#9166)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Can't get this to work with computed / created

For some reason this seems to cause my Jest tests to break.

I'm testing a fairly simple component. If I don't mock the store, then I don't get these errors. With the mock store, the Jest tests will work provided that this is not referenced within computed or created (and no I'm not using arrow functions). Somehow the mock runs causes those hooks to run without this context.

(btw: I would have made a JsFiddle but I can't figure out how to set up Jest and Vuex and this library in JsFiddle. Maybe you could add a starting link to the new issue template?)

Here's the component code:

<template lang="pug">
  q-toolbar
    q-btn(flat='', dense='', round='', @click='toggleLeftDrawer', aria-label='Menu')
      q-icon(name='menu')
    q-toolbar-title
      .title Mobile Notary Register
      .subtitle
        | {{ locale }} Dev: {{ !!dev }} Desktop:
        | {{ !!$q.platform.is.desktop }} iPad:
        | {{ !!$q.platform.is.ipad }}
    v-offline.v-offline(online-class='online', offline-class='offline', @detected-condition='amIOnline')
      //- template(v-slot:[onlineSlot] slot-name="onlineSlot") 
    q-icon(:class="{'status-indicator': true,online: networkOnline,offline: !networkOnline}" name="fas fa-wifi")
    q-icon(:class="{'status-indicator': true,online: serverOnline,offline: !serverOnline}" name="fas fa-server")

</template>

<script>
  import VOffline from "v-offline";
  import { mapActions } from "vuex";
  import * as types from "src/store/mutation-types";
  export default {
    name: "ToolBar",
    components: { VOffline },
    data() {
      return {
        dev: process.env.DEV,
        locale: this.$q.lang.getLocale(),
        onlineSlot: "online",
        offlineSlot: "offline"
      };
    },
    computed: {
      networkOnline() {
        return this.$store.state.pings.networkOnline;
      },
      serverOnline() {
        return this.$store.state.pings.serverOnline;
      }
    },
    created() {
       console.log(this)
    },

I've tried various formats for the computed methods... i.e. as above, also with the extended function syntax and lastly with the get() and set() syntax – always the same result.

Here's the test:

import Vuex from "vuex";
import VueRouter from "vue-router";
import { mount, shallowMount, createLocalVue } from "@vue/test-utils";
import { Store } from "vuex-mock-store";
import Component from "../tool-bar.vue";
import * as All from "quasar";
import storeIndex from "src/store";
import pings from "src/store/pings";
import shared from "src/store/pings";
import _ from "lodash";

const store = new Store({
  modules: {
    pings,
    shared
  }
});
// const store = storeIndex;
const mocks = {
  $store: store
};
let wrapper;
const localVue = createLocalVue();
const { Quasar, date } = All;
const router = new VueRouter();
const components = Object.keys(All).reduce((object, key) => {
  const val = All[key];
  if (val && val.component && val.component.name != null) {
    object[key] = val;
  }
  return object;
}, {});

localVue.use(Vuex);
localVue.use(VueRouter);
localVue.use(Quasar, { components }); // , lang: langEn

describe("Component", () => {
  beforeEach(() => {
    console.log("Component test");
    wrapper = mount(Component, {
      store,
      localVue,
      router
    });
  });

  afterEach(() => {
    wrapper.destroy();
    // store.reset();
    jest.restoreAllMocks();
  });

  it("is a Vue instance", () => {
    expect(wrapper.isVueInstance()).toBeTruthy();
  });

Here's the error message and stack where it blows up like Wuhan:

  console.error node_modules/vue/dist/vue.common.dev.js:630
    [Vue warn]: Error in render: "TypeError: Cannot read property 'networkOnline' of undefined"

    found in

    ---> <ToolBar>
           <Root>

  console.error node_modules/vue/dist/vue.common.dev.js:1893
    TypeError: Cannot read property 'networkOnline' of undefined
        at VueComponent.networkOnline (/Users/me/project1/src/components/shared/tool-bar.vue:35:1)
        at Watcher.get (/Users/me/project1/node_modules/vue/dist/vue.common.dev.js:4474:25)
        at Watcher.evaluate (/Users/me/project1/node_modules/vue/dist/vue.common.dev.js:4579:21)
        at Proxy.computedGetter (/Users/me/project1/node_modules/vue/dist/vue.common.dev.js:4828:17)
        at Proxy.render (/Users/me/project1/src/components/shared/tool-bar.vue:153:757)
        at VueComponent.Vue._render (/Users/me/project1/node_modules/vue/dist/vue.common.dev.js:3547:22)
        at VueComponent.updateComponent (/Users/me/project1/node_modules/vue/dist/vue.common.dev.js:4063:21)
        at Watcher.get (/Users/me/project1/node_modules/vue/dist/vue.common.dev.js:4474:25)
        at new Watcher (/Users/me/project1/node_modules/vue/dist/vue.common.dev.js:4463:12)
        at mountComponent (/Users/me/project1/node_modules/vue/dist/vue.common.dev.js:4070:3)
        at VueComponent.Object.<anonymous>.Vue.$mount (/Users/me/project1/node_modules/vue/dist/vue.common.dev.js:9040:10)
        at VueComponent.Object.<anonymous>.Vue.$mount (/Users/me/project1/node_modules/vue/dist/vue.common.dev.js:11940:16)
        at init (/Users/me/project1/node_modules/vue/dist/vue.common.dev.js:3121:13)
        at createComponent (/Users/me/project1/node_modules/vue/dist/vue.common.dev.js:5969:9)
        at createElm (/Users/me/project1/node_modules/vue/dist/vue.common.dev.js:5916:9)
        at VueComponent.patch [as __patch__] (/Users/me/project1/node_modules/vue/dist/vue.common.dev.js:6466:7)
        at VueComponent.Vue._update (/Users/me/project1/node_modules/vue/dist/vue.common.dev.js:3942:19)
        at VueComponent.updateComponent (/Users/me/project1/node_modules/vue/dist/vue.common.dev.js:4063:10)
        at Watcher.get (/Users/me/project1/node_modules/vue/dist/vue.common.dev.js:4474:25)
        at new Watcher (/Users/me/project1/node_modules/vue/dist/vue.common.dev.js:4463:12)
        at mountComponent (/Users/me/project1/node_modules/vue/dist/vue.common.dev.js:4070:3)
        at VueComponent.Object.<anonymous>.Vue.$mount (/Users/me/project1/node_modules/vue/dist/vue.common.dev.js:9040:10)
        at VueComponent.Object.<anonymous>.Vue.$mount (/Users/me/project1/node_modules/vue/dist/vue.common.dev.js:11940:16)
        at mount (/Users/me/project1/node_modules/@vue/test-utils/dist/vue-test-utils.js:13528:21)
        at Object.<anonymous> (/Users/me/project1/src/components/shared/__tests__/tool-bar_jest.spec.js:50:15)
        at Object.asyncJestLifecycle (/Users/me/project1/node_modules/jest-jasmine2/build/jasmineAsyncInstall.js:53:37)
        at /Users/me/project1/node_modules/jest-jasmine2/build/queueRunner.js:43:12
        at new Promise (<anonymous>)
        at mapper (/Users/me/project1/node_modules/jest-jasmine2/build/queueRunner.js:26:19)
        at /Users/me/project1/node_modules/jest-jasmine2/build/queueRunner.js:73:41
        at processTicksAndRejections (internal/process/task_queues.js:85:5)

I'm not sure if this is a bug or just me doing it wrong.

An in-range update of vue-template-compiler is breaking the build 🚨

The devDependency vue-template-compiler was updated from 2.5.18 to 2.5.19.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

vue-template-compiler is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ci/circleci: build: Your tests failed on CircleCI (Details).

Release Notes for v2.5.19

Bug Fixes

  • ssr: should not warn for custom directives that do not have ssr implementation 780dac5, closes #9167
  • vdom: remove unnecessary sameVnode condition 0d4b35f, closes #9168

Reverts

  • fix(sfc): avoid deindent when pad option is specified (#7647) 5d721a4, closes #7647
FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Cannot find namespace 'jest'

Hi there. I've noticed this issue while running my Nuxt app. This not affects any of my tests but appears always during build process.

vuex-mock-store/src/index.d.ts(15,68):

15:68 Cannot find namespace 'jest'.
    13 | }
    14 |
  > 15 | export class Store<S extends Dict = {}, G extends Dict = {}, Spy = jest.Mock> {
       |                                                                    ^
    16 |   commit: Spy
    17 |   dispatch: Spy
    18 |   state: S

Unable to access store in composition api

All my components use store like so, const store = useStore();

in my jest.setup.js I have,

const state = { site: { id: 1, }, post: { data: [], },...

const getters = { 'site/getSite': { id: 1, created: null,...

and this is how I provide the mock store, following the docs

const store = new Store({ state, getters });
config.global.mocks.$store = store;

But I'm stuck with

multiple [Vue warn]: injection "store" not found.

Now, my question is, is there a function like injectRouterMock in vue-router-mock which can be used or how do I provide the injection (useStore uses injection internally, I think)

I tried the provide option on global but with no luck, maybe I'm missing something?

PS. it was working with the following implementation,

const store = createStore({ modules: { site,... } })
config.global.plugins = [store]
config.global.provide = { [Symbol('mock-store')]: store }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.