Skip to content

Instantly share code, notes, and snippets.

@harrybeckwith
Created November 8, 2019 15:29
Show Gist options
  • Select an option

  • Save harrybeckwith/dc19c23716bf8651f1bf5d3f566a735b to your computer and use it in GitHub Desktop.

Select an option

Save harrybeckwith/dc19c23716bf8651f1bf5d3f566a735b to your computer and use it in GitHub Desktop.

Revisions

  1. harrybeckwith created this gist Nov 8, 2019.
    49 changes: 49 additions & 0 deletions modal.spec.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,49 @@
    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
    });

    component = shallowMount(Modal, {
    store,
    localVue,
    });
    });

    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
    });
    });
    });
    });