Files
ghibli-api/store/films/actions.spec.js
2020-12-21 14:10:33 +01:00

36 lines
794 B
JavaScript

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: Cannot read property '$get' of null"
);
});
});