test loading.tsx files
Answered
Jumbo flying squid posted this in #help-forum
Jumbo flying squidOP
Hey guys, whats the strategy to test loading.tsx file renders? Specifically just want to see the layout!
Answered by B33fb0n3
inside your page.tsx create a new Promise that resolves after x seconds. Like that you can build a delay in that the page loads and then you can see the loading.tsx. A delay could look like this:
export const delay = async (timeInSec: number) => {
const abc = await new Promise((resolve) => setTimeout(resolve, timeInSec * 1000));
return true;
}8 Replies
@Jumbo flying squid Hey guys, whats the strategy to test loading.tsx file renders? Specifically just want to see the layout!
inside your page.tsx create a new Promise that resolves after x seconds. Like that you can build a delay in that the page loads and then you can see the loading.tsx. A delay could look like this:
export const delay = async (timeInSec: number) => {
const abc = await new Promise((resolve) => setTimeout(resolve, timeInSec * 1000));
return true;
}Answer
another way is to get the react dev tools and force suspense on element: https://react-devtools-tutorial.vercel.app/toggling-suspense-fallbacks
@Jumbo flying squid solved?
@Jumbo flying squid ?
Jumbo flying squidOP
sorry will try tonight, been busy with irl work!
@riský another way is to get the react dev tools and force suspense on element: <https://react-devtools-tutorial.vercel.app/toggling-suspense-fallbacks>
Jumbo flying squidOP
does toggling suspense work if the component isnt wrapped in suspense? Not sure if next uses suspense under the hood for the loading.tsx
yeah loading.tsx does use suspense
Jumbo flying squidOP
ah cool ok. The promise way also worked! Lots of good options 🙂 thanks all. sorry for the delay, had some irl stuff happen.