Skip to content

Commit

Permalink
first try of a test, doesn't work yet
Browse files Browse the repository at this point in the history
  • Loading branch information
IrisOlfermann committed Jan 15, 2024
1 parent 91db493 commit 8a470b1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Resources/src/api/getParticipationsByDay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const listDataState = ref([])
* @param date
* @returns list of participants
*/
export function useParticipationsListData(date: string){
export default function useParticipationsListData(date: string){

const loaded = ref(false)

Expand Down
28 changes: 28 additions & 0 deletions src/Resources/tests/unit/api/getParticipationsByDate.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import useApi from "@/api/api";
import Participations from "../fixtures/participationsByDate.json";
import useParticipationsListData from "@/api/getParticipationsByDay";
import { ref } from "vue";

const asyncFunc: () => Promise<void> = async () => {
new Promise(resolve => resolve(undefined));
};

const mockedReturnValue = {
response: ref(Participations),
request: asyncFunc,
error: ref(false)
}

// @ts-expect-error ts doesn't like mocking with jest.fn()
useApi = jest.fn(useApi);
// @ts-expect-error continuation of expect error from line above
useApi.mockReturnValue(mockedReturnValue);

describe('Test getParticipations', () => {
it('should return a list of participations', async () => {
const { listData } = useParticipationsListData("16/01/2024");

// expect(error.value).toBeFalsy();
expect(listData).toEqual(Participations);
});
});
10 changes: 10 additions & 0 deletions src/Resources/tests/unit/fixtures/participationsByDate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
"Alice Meals",
"Bob Meals",
"John Meals",
"Admin Meals",
"Finance Meals",
"Kochomi Meals",
"Jane Meals"
]

0 comments on commit 8a470b1

Please sign in to comment.