Skip to content

Instantly share code, notes, and snippets.

@harrybeckwith
Created November 8, 2019 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harrybeckwith/8cd5ddb04b241bc58b581fd5c79843c9 to your computer and use it in GitHub Desktop.
Save harrybeckwith/8cd5ddb04b241bc58b581fd5c79843c9 to your computer and use it in GitHub Desktop.
Testing a component that has vuex
import Vuex from "vuex";
import { createLocalVue, shallowMount } from "@vue/test-utils";
import chai, { expect } from "chai";
import sinon from "sinon";
import sinonChai from "sinon-chai";
import Modal from "@/ui/Modal";
import BaseButton from "@/ui/BaseButton";
chai.use(sinonChai);
const localVue = createLocalVue();
localVue.use(Vuex);
localVue.component("BaseButton", BaseButton);
describe("Modal", () => {
let store;
const getters = {
isModalOpen: () => true,
activeModalName: () => "baz"
};
const actions = {
TOGGLE_MODAL: () => true
};
let component;
const mockMethod = sinon.spy();
beforeEach(() => {
store = new Vuex.Store({
getters,
actions
});
const name = "baz";
component = shallowMount(Modal, {
store,
localVue,
propsData: {
name: name
},
mocks: {
$t: () => {}
}
});
});
describe("can close when", () => {
it("clicking 'x'", () => {
component.setMethods({ TOGGLE_MODAL: mockMethod });
component.find(".modal-close-btn").trigger("click");
expect(mockMethod).to.have.been.called.calledWith({
isOpen: false,
name: null
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment