Mocking Prismic in Jest

Has anyone successfully mocked any aspect of the prismic-javascript library.

I am wanting to mock the response from the query function on the Api object received from getApi. This is so I can test our response should the query timeout now that we can pass a timeout argument.

I can mock the getApi or Predicates functionality but not query function.

1 Like

Hello @david.halewood, for the moment we don’t have any example showing how to test. I’ve found a cool article that explains how to make API tests with Jest.

I hope it helps you!

Hey thanks,

Yeah, no worries. The nuance that we are struggling with is the typings in typescript and the fact we have to mock an instance of ResolvedApi. This is so we can mock .query and test our behaviour. All good, we are working on it.