W
Wasp•10mo ago
Supreme

How to test delete function in open sass starter template

Hello I am new to wasp and im trying to figure out how to properly unit test the front end. I have an initial test that is passing, that tests the getAllTasksByUser query returns the tasks and renders to the front end. My failing test is supposed to follow a similar format as the first. Mock the function to return the expected data but im having trouble with a typescript error when passing in deleteTask to mockQuery -> "Argument of type 'Promise<GetResult<{ id: string; description: string; time: string; isDone: boolean; userId: number; createdAt: Date; }, unknown> & {}>' is not assignable to parameter of type 'Query<unknown, unknown>'. Type 'Promise<GetResult<{ id: string; description: string; time: string; isDone: boolean; userId: number; createdAt: Date; }, unknown> & {}>' provides no match for the signature '(queryCacheKey: string[], args: unknown): Promise<unknown>'.ts(2345)"
No description
7 Replies
Supreme
SupremeOP•10mo ago
my guess is that its because deleteTask is an action and not a query ? its incompatible ? been doing research and think i need to use mockApi
miho
miho•10mo ago
Testing | Wasp
Wasp is in beta, so keep in mind there might be some kinks / bugs, and possibly some changes with testing support in the future. If you encounter any issues, reach out to us on Discord and we will make sure to help you out!
miho
miho•10mo ago
I believe what you should write is: mockQuery(deleteTask, {})
Supreme
SupremeOP•10mo ago
When i add that line to my test a get a ts error: Argument of type '(args: Pick<GetResult<{ id: string; description: string; time: string; isDone: boolean; userId: number; createdAt: Date; }, unknown> & {}, "id">) => Promise<GetResult<{ id: string; description: string; time: string; isDone: boolean; userId: number; createdAt: Date; }, unknown> & {}>' is not assignable to parameter of type 'Query<unknown, GetResult<{ id: string; description: string; time: string; isDone: boolean; userId: number; createdAt: Date; }, unknown> & {}>'. Types of parameters 'args' and 'queryCacheKey' are incompatible. Property 'id' is missing in type 'string[]' but required in type 'Pick<GetResult<{ id: string; description: string; time: string; isDone: boolean; userId: number; createdAt: Date; }, unknown> & {}, "id">'.ts(2345)
MEE6
MEE6•10mo ago
Wohooo @Supreme, you just became a Waspeteer level 1!
Supreme
SupremeOP•10mo ago
really having trouble deciphering how its supposed to be formatted to get rid of the ts error i want to write a unit test for the deleteTask method. I want to mock the method and when the user clicks the button I want to verify that it was called and called with the correct paramater. Would you advise using Vitest for this type of test or can i rely on wasp methods to cover this ? Any guidance really helps, thanks. Solved my failing test. I ended up using vitest to mock the wasp operation methods. I think I was not using the wasp helper methods in the correct context for what i was trying to do with my test.
Vinny (@Wasp)
Vinny (@Wasp)•10mo ago
Nice. good to hear. Let us know if you have any other questions 🙂
Want results from more Discord servers?
Add your server