Files
ghibli-api/pages/vehicles/_id.spec.js

57 lines
1.3 KiB
JavaScript

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