import { mount, createLocalVue } from "@vue/test-utils"; import Vuex from "vuex"; import Location from "./_id"; import mockLocations from "@/test/fake-locations.json"; let $route = { path: "/locations", params: { id: "2baf70d1-42bb-4437-b551-e5fed5a87abe" } }; const localVue = createLocalVue(); localVue.use(Vuex); describe("Location page", () => { let state, actions, store; beforeEach(() => { state = { location: {} }; actions = { getLocation: jest.fn() }; store = new Vuex.Store({ modules: { locations: { namespaced: true, state, actions } } }); }); it("should render Location page instance", () => { const wrapper = mount(Location, { localVue, store, computed: { location: () => mockLocations[0] } }); expect(wrapper.exists()).toBe(true); }); it("tests params validation", () => { expect(Location.validate({ params: $route.params })).toBe(true); expect( Location.validate({ params: { id: "2baf70d1-42bb-4437-b551-e5fed5a87abe-1234" } }) ).toBe(false); expect( Location.validate({ params: { id: "2baf7e0d1-42bb-4437-b551-e5fed5a87abe" } }) ).toBe(false); }); it("should dispatch getLocation action", async () => { let wrapper = mount(Location, { localVue, store, computed: { location: () => mockLocations[0] } }); await wrapper.vm.$options.asyncData({ store, params: $route.params }); expect(actions.getLocation).toHaveBeenCalled(); }); });