How to (mock) test external API request that happens inside Next.js getStaticProps

Viewed 606

I'm using cypress to test my Next.js build.

As the point of getStaticProps, a query is made to an external API and the data returned is formatted and then passed as props to the component.

I know getStaticProps happens at build time / revalidation time so this makes it difficult to test at the component level (as the query has already been completed).

Does anyone know the best approach here? Can I pass fake props to the component somehow? And then test the component with cypress?

0 Answers
Related