Create vuex modules for Films/Vehicles/Locations/People + Test adaptation

This commit is contained in:
2020-12-21 12:01:36 +01:00
parent d8cfe69fa0
commit fffbc87964
12 changed files with 172 additions and 95 deletions

View File

@@ -0,0 +1,35 @@
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."
);
});
});