Tested all fruit mutations
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user