How to specify request input when testing? #755
-
I'm new to the library and I cannot seem to make a test that needs input to pass. Its simples, my endpoint is this one: export const needsInput = defaultEndpointsFactory.build({
method: "post",
input: z.object({
sampleInput: z.string().min(6),
}),
output: z.object({
validation: z.string(),
}),
handler: async ({ input, logger }) => {
return {
validation: "Input successully validated",
};
},
}); On my test suite how should I specify the "sampleInput" property? Tried in many different ways and never actually got it right. The docs says "parsed JSON" on the body field but what actually parsed JSON means in that context? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Nevermind i Just noticed that I've forgot the method property on my test, sorry hahaha |
Beta Was this translation helpful? Give feedback.
-
Hello @SamuelPires1999 , sorry for the unclarity. The real IO workflow receives the request body as a string and uses
Yeah, the default request method is Best wishes. |
Beta Was this translation helpful? Give feedback.
Hello @SamuelPires1999 ,
sorry for the unclarity.
For testing your endpoints use the exposed method
testEndpoint()
havingjest
and@types/jest
installed.By "parsed JSON" in the
body
prop of that method I implied that the requestbody
should be anobject
instead of astring
.The real IO workflow receives the request body as a string and uses
body-parser
to process it: in particular case — the JSON parser.However, in testing workflow this step is skipped, so you should supply body the way it would be after parsing the JSON string — as object.
Anyway, it's easier for the development as well.
Yeah, the …