import { actions } from "./"; import axios from "axios"; import mockFilms from "@/test/fake-films.json"; let url = ""; jest.mock("axios", () => ({ $get: _url => { return new Promise(resolve => { url = _url; resolve(mockFilms); }); } })); describe("Vuex actions.", () => { it("tests films/getList action.", async () => { const commit = jest.fn(); actions.$axios = axios; await actions.getList({ commit }); expect(url).toBe("/api/films"); expect(commit).toHaveBeenCalledWith("setList", mockFilms); }); it("catches errors.", async () => { const commit = jest.fn(); actions.$axios = null; await expect(actions.getList({ commit })).rejects.toThrow( "API Error occurred." ); }); });