#Testing Hooks & Jobs

8 messages · Page 1 of 1 (latest)

signal socket
#

Guys, do you recommend any approach for testing hooks?
Are there any examples out there? I’ve only seen two tests in the Blank template, but they seem focused only on Frontend and Custom Endpoints.

paper ferryBOT
lunar garden
#

Tests are good 🙇

dry ember
#

I would just test them as regular JavaScript functions / components

signal socket
#

for example?

dry ember
#

you test it as you would any other JavaScript function, mocking payload like usual

lunar garden
#

There is a bit of casting required for TS, but yeah it should be like testing any other JS

export type BeforeValidateFromT = FieldHook<
  Redirect,
  NonNullable<Redirect['to']>['url'],
  Redirect['to']
>
...
expect(
  beforeValidateFrom({ value: input1 } as BeforeValidateFromT['arguments']),
).toStrictEqual(output1)