Files
ghibli-api/pages/films/index.spec.js
2020-12-18 03:44:26 +01:00

38 lines
947 B
JavaScript

import { mount, shallowMount } from "@vue/test-utils";
import axios from "axios";
import FilmsView from "./";
import mockFilms from "@/test/fake-films.json";
jest.mock("axios", () => ({
$get: jest.fn(() => mockFilms)
}));
describe("Films page", () => {
it("should render Films page instance", () => {
const wrapper = mount(FilmsView);
expect(wrapper.find("img").exists()).toBe(true);
});
it("should get films from Ghibli API", async () => {
let wrapper = shallowMount(FilmsView, {
mocks: {
$axios: axios
}
});
expect((await wrapper.vm.$options.asyncData(wrapper.vm)).films).toEqual(
mockFilms
);
// Init page with mocked asyncData
wrapper = shallowMount(FilmsView, {
mocks: {
films: (await wrapper.vm.$options.asyncData(wrapper.vm)).films,
$axios: axios
}
});
expect(wrapper.findComponent({ name: "Grid" }).exists()).toBe(true);
});
});