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