From bca6a2ed115a7eb7bfbb116c57a42662791a01d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Viricel?= Date: Thu, 17 Dec 2020 19:31:25 +0100 Subject: [PATCH] Create Grid component + Test. Index test adaptations --- components/Grid.vue | 19 +++++++++++++++++++ pages/films/index.vue | 8 +++++++- test/Grid.spec.js | 23 +++++++++++++++++++++++ test/index.spec.js | 8 ++++---- 4 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 components/Grid.vue create mode 100644 test/Grid.spec.js diff --git a/components/Grid.vue b/components/Grid.vue new file mode 100644 index 0000000..a991e15 --- /dev/null +++ b/components/Grid.vue @@ -0,0 +1,19 @@ + + + + + diff --git a/pages/films/index.vue b/pages/films/index.vue index 9c5480e..73805ef 100644 --- a/pages/films/index.vue +++ b/pages/films/index.vue @@ -3,19 +3,25 @@

Ghibli films

-
{{ films }}
+ diff --git a/test/Grid.spec.js b/test/Grid.spec.js new file mode 100644 index 0000000..4f012fd --- /dev/null +++ b/test/Grid.spec.js @@ -0,0 +1,23 @@ +import { mount } from "@vue/test-utils"; +import Grid from "@/components/Grid"; +import mockFilms from "./fake-films.json"; + +describe("Grid", () => { + it("tests props", () => { + expect(Grid.props).toMatchObject({ + dataSource: { + type: Array, + required: true + } + }); + }); + + it("should render Grid instance", () => { + const wrapper = mount(Grid, { + propsData: { + dataSource: mockFilms + } + }); + expect(JSON.parse(wrapper.text())).toEqual(mockFilms); + }); +}); diff --git a/test/index.spec.js b/test/index.spec.js index 3158fc5..0c72af5 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -1,4 +1,4 @@ -import { mount } from "@vue/test-utils"; +import { mount, shallowMount } from "@vue/test-utils"; import axios from "axios"; import FilmsView from "@/pages/films"; import mockFilms from "./fake-films.json"; @@ -14,7 +14,7 @@ describe("Films page", () => { }); it("should get films from Ghibli API", async () => { - let wrapper = mount(FilmsView, { + let wrapper = shallowMount(FilmsView, { mocks: { $axios: axios } @@ -25,13 +25,13 @@ describe("Films page", () => { ); // Init page with mocked asyncData - wrapper = mount(FilmsView, { + wrapper = shallowMount(FilmsView, { mocks: { films: (await wrapper.vm.$options.asyncData(wrapper.vm)).films, $axios: axios } }); - expect(JSON.parse(wrapper.find(".films").text())).toEqual(mockFilms); + expect(wrapper.findComponent({ name: "Grid" }).exists()).toBe(true); }); });