Add jest coverage + Test setFruits mutation

This commit is contained in:
2020-12-03 23:37:02 +01:00
parent 69e0f90c5a
commit 59c085f4d5
20 changed files with 1345 additions and 4 deletions

View File

@@ -1,5 +1,6 @@
import { mount } from "@vue/test-utils";
import mockAxios from "axios";
import { mount } from "@vue/test-utils";
import App from "../../src/App.vue";
import Fruits from "../../src/views/Fruits.vue";
@@ -15,6 +16,7 @@ describe("App", () => {
});
});
// TODO: Move the following code to fruits.spec.js
jest.mock("axios", () => ({
get: jest.fn(() => Promise.resolve({ data: { data: "value" } }))
}));

View File

@@ -0,0 +1,36 @@
import mutations from "@/store/mutations.js";
describe("Test Vuex mutations.", () => {
it("should add fruits to the state", () => {
const fruits = [
{
id: 3,
isFruit: true,
name: "banana",
image: "/image/path.jpg",
price: "907.00",
color: "#763e44",
description: "Iusto illum vero voluptatem.",
taste: "Handcrafted",
expires: "2021-04-11T08:54:24.588Z"
}
];
const state = {
fruits: []
};
mutations.setFruits(state, fruits);
expect(state.fruits).toEqual([
{
id: 3,
isFruit: true,
name: "banana",
image: "/image/path.jpg",
price: "907.00",
color: "#763e44",
description: "Iusto illum vero voluptatem.",
taste: "Handcrafted",
expires: "2021-04-11T08:54:24.588Z"
}
]);
});
});