Tested all fruit mutations

This commit is contained in:
2020-12-03 23:54:59 +01:00
parent 59c085f4d5
commit 4b1ac294bd
6 changed files with 61 additions and 43 deletions

View File

@@ -1,36 +1,43 @@
import mutations from "@/store/mutations.js";
import { state } from "@/store";
import mutations from "@/store/mutations";
const { setFruits, setFruit, addFruit, removeFruit } = mutations;
let fruit = {
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"
};
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"
}
]);
it("tests setFruits mutation.", () => {
setFruits(state, [fruit]);
expect(state.fruits[0].id).toBe(3);
});
it("tests setFruit mutation.", () => {
setFruit(state, fruit);
expect(state.fruit.id).toBe(3);
});
it("tests addFruit mutation.", () => {
const newFruit = Object.assign({}, fruit);
newFruit.id = 4;
addFruit(state, newFruit);
expect(state.fruits[0].id).toBe(3);
expect(state.fruits[1].id).toBe(4);
expect(state.fruits.length).toBe(2);
});
it("tests removeFruit mutation.", () => {
removeFruit(state, 4);
expect(state.fruits[0].id).toBe(3);
expect(state.fruits.length).toBe(1);
});
});