Log value in Deno, then read from console

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:

  1. Run your script with the --inspect flag:
deno run --inspect your_script.ts
  1. Open Chrome and go to chrome://inspect. Click on the Open dedicated DevTools for Node link.
  2. In the newly opened DevTools window, click on the Console tab.
  3. Run your script and watch the console output in the DevTools console.

Note: The --inspect flag allows you to debug your Deno script using Chrome DevTools, including setting breakpoints, stepping through code, and watching variables.