Created
November 8, 2019 14:44
-
-
Save harrybeckwith/8cd5ddb04b241bc58b581fd5c79843c9 to your computer and use it in GitHub Desktop.
Testing a component that has vuex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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