import { actions, mutations } from "@/store"; 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 getFilms action.", async () => { const commit = jest.fn(); actions.$axios = axios; await actions.getFilms({ commit }); expect(url).toBe("/api/films"); expect(commit).toHaveBeenCalledWith("setFilms", mockFilms); }); it("catches errors.", async () => { const commit = jest.fn(); actions.$axios = null; await expect(actions.getFilms({ commit })).rejects.toThrow( "API Error occurred." ); }); });