44 lines
1.1 KiB
JavaScript
44 lines
1.1 KiB
JavaScript
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("Vuex mutations.", () => {
|
|
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);
|
|
});
|
|
});
|