UNCLASSIFIED

Commit 10a7f324 authored by graham.smith's avatar graham.smith
Browse files

fix error messages in Training.spec

parent 3d2362b6
...@@ -3,10 +3,9 @@ import Training from "@/views/super-admin/Training.vue"; ...@@ -3,10 +3,9 @@ import Training from "@/views/super-admin/Training.vue";
import TrainingService from "@/api/services/training"; import TrainingService from "@/api/services/training";
describe("Training", () => { describe("Training", () => {
const mockCoursesResult = { courses: [], meta: { total: 0 } };
it("should debounce getCourses", async () => { it("should debounce getCourses", async () => {
TrainingService.getCourses = jest TrainingService.getCourses = jest.fn().mockResolvedValue(mockCoursesResult);
.fn()
.mockResolvedValue({ items: [], total: 0 });
const wrapper = shallowMount(Training); const wrapper = shallowMount(Training);
wrapper.vm.fetchDebounced(); wrapper.vm.fetchDebounced();
...@@ -31,6 +30,7 @@ describe("Training", () => { ...@@ -31,6 +30,7 @@ describe("Training", () => {
}); });
it("should handle error on getCourses", async () => { it("should handle error on getCourses", async () => {
console.error = jest.fn(); // mock console.error when expecting error messages
TrainingService.getCourses = jest.fn().mockRejectedValue("mock error"); TrainingService.getCourses = jest.fn().mockRejectedValue("mock error");
const wrapper = shallowMount(Training); const wrapper = shallowMount(Training);
...@@ -65,26 +65,33 @@ describe("Training", () => { ...@@ -65,26 +65,33 @@ describe("Training", () => {
// }); // });
// //
it("should remove selected courses", async () => { describe("remove courses", () => {
TrainingService.deleteCourses = jest.fn().mockResolvedValue(); it("should remove selected courses", async () => {
TrainingService.deleteCourses = jest.fn().mockResolvedValue();
const wrapper = shallowMount(Training); const wrapper = shallowMount(Training);
const mockCourses = [{ name: "mock course1" }, { name: "mock course2" }]; const mockCourses = [{ name: "mock course1" }, { name: "mock course2" }];
wrapper.vm.selectedCourses = mockCourses; wrapper.vm.selectedCourses = mockCourses;
await wrapper.vm.removeSelected(); await wrapper.vm.removeSelected();
expect(TrainingService.deleteCourses).toHaveBeenCalledTimes(1); expect(TrainingService.deleteCourses).toHaveBeenCalledTimes(1);
expect(TrainingService.deleteCourses).toHaveBeenCalledWith(mockCourses); expect(TrainingService.deleteCourses).toHaveBeenCalledWith(mockCourses);
expect(wrapper.vm.snackbars.delete).toEqual(true); expect(wrapper.vm.snackbars.delete).toEqual(true);
expect(wrapper.vm.state.isDeleting).toEqual(false); expect(wrapper.vm.state.isDeleting).toEqual(false);
expect(wrapper.vm.selectedCourses).toHaveLength(0); expect(wrapper.vm.selectedCourses).toHaveLength(0);
});
// error state it("should remove selected courses", async () => {
TrainingService.deleteCourses = jest.fn().mockRejectedValue("mock error"); console.error = jest.fn(); // mock console.error when expecting error messages
await wrapper.vm.removeSelected(); TrainingService.deleteCourses = jest.fn().mockResolvedValue();
expect(wrapper.vm.snackbars.delete).toEqual(false);
expect(wrapper.vm.state.isDeleting).toEqual(false); const wrapper = shallowMount(Training);
expect(wrapper.vm.selectedCourses).toHaveLength(0);
TrainingService.deleteCourses = jest.fn().mockRejectedValue("mock error");
await wrapper.vm.removeSelected();
expect(wrapper.vm.snackbars.delete).toEqual(false);
expect(wrapper.vm.state.isDeleting).toEqual(false);
expect(wrapper.vm.selectedCourses).toHaveLength(0);
});
}); });
it("should compute css class for courses", async () => { it("should compute css class for courses", async () => {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment