How can I read a value logged to the console in Deno for testing purposes?
I need to be able to check if a function logs the right value to the console.
I have tried using Getting values from Deno stdin, but it only works for values manually typed into stdin.
Is there a way to read values logged to the console in Deno?
Yes, you can use the
--inspect flag when running your Deno script, and then use a debugger like Chrome DevTools to view the console output. Here are the steps:
- Run your script with the
deno run --inspect your_script.ts
- Open Chrome and go to
chrome://inspect. Click on the
Open dedicated DevTools for Node link.
- In the newly opened DevTools window, click on the
- Run your script and watch the console output in the DevTools console.
--inspect flag allows you to debug your Deno script using Chrome DevTools, including setting breakpoints, stepping through code, and watching variables.