Files
ghibli-api/store/films/actions.spec.js
2020-12-21 22:06:05 +01:00

38 lines
865 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?fields=id,title,release_date,director,description,rt_score"
);
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"
);
});
});