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

57 lines
1.2 KiB
JavaScript

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