<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Shubham Bajaj</title>
    <description>The latest articles on Forem by Shubham Bajaj (@bajajcodes).</description>
    <link>https://forem.com/bajajcodes</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1025750%2F51262a75-d6b6-4628-a7c4-10ae6b611072.jpg</url>
      <title>Forem: Shubham Bajaj</title>
      <link>https://forem.com/bajajcodes</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/bajajcodes"/>
    <language>en</language>
    <item>
      <title>Vocode Setup for GenAI Voice Calls: A Guide for Non-Python Developers</title>
      <dc:creator>Shubham Bajaj</dc:creator>
      <pubDate>Fri, 24 May 2024 17:51:37 +0000</pubDate>
      <link>https://forem.com/bajajcodes/vocode-setup-for-genai-voice-calls-a-guide-for-non-python-developers-4f21</link>
      <guid>https://forem.com/bajajcodes/vocode-setup-for-genai-voice-calls-a-guide-for-non-python-developers-4f21</guid>
      <description>&lt;p&gt;&lt;strong&gt;Target Audience:&lt;/strong&gt; This guide is designed for developers who are not primarily familiar with Python or its ecosystem, and want to set up Vocode for GenAI voice calls.&lt;/p&gt;

&lt;h2&gt;Table of Contents&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Introduction to Vocode and Project Tools&lt;/li&gt;
  &lt;li&gt;Project Setup and Dependency Management&lt;/li&gt;
  &lt;li&gt;Configuring Environment Variables and Ngrok&lt;/li&gt;
  &lt;li&gt;Setting Up the Telephony Server&lt;/li&gt;
  &lt;li&gt;Creating the Outbound Call Script&lt;/li&gt;
  &lt;li&gt;Additional Notes and Troubleshooting&lt;/li&gt;
  &lt;li&gt;References&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;1. Introduction to Vocode and Project Tools&lt;/h2&gt;

&lt;p&gt;Vocode is a powerful tool for creating AI-powered voice applications. To streamline the development process, we'll use:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
&lt;strong&gt;Poetry:&lt;/strong&gt; For managing project dependencies and virtual environments.&lt;/li&gt;
  &lt;li&gt;
&lt;strong&gt;Pyproject.toml:&lt;/strong&gt; A configuration file used by Poetry to define project details, Python version, and required libraries.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;2. Project Setup and Dependency Management&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;
&lt;strong&gt;Install Poetry:&lt;/strong&gt;
   Follow the instructions on the &lt;a href="https://python-poetry.org/docs/#installation" rel="noopener noreferrer"&gt;Poetry installation page&lt;/a&gt;.&lt;/li&gt;

  &lt;li&gt;
&lt;strong&gt;Create the Project:&lt;/strong&gt;

&lt;pre&gt;&lt;code&gt;poetry new project-name&lt;/code&gt;&lt;/pre&gt;
  &lt;/li&gt;

  &lt;li&gt;
&lt;strong&gt;Activate the Virtual Environment:&lt;/strong&gt;

&lt;pre&gt;&lt;code&gt;poetry config virtualenvs.create true
poetry shell&lt;/code&gt;&lt;/pre&gt;
  &lt;/li&gt;

  &lt;li&gt;
&lt;strong&gt;Specify the Python Version:&lt;/strong&gt;

    &lt;ul&gt;
      &lt;li&gt;Open &lt;code&gt;pyproject.toml&lt;/code&gt; in your project directory.&lt;/li&gt;
      &lt;li&gt;Add the following under &lt;code&gt;[tool.poetry.dependencies]&lt;/code&gt;:

&lt;pre&gt;&lt;code&gt;python = "&amp;gt;=3.9,&amp;lt;3.12"&lt;/code&gt;&lt;/pre&gt;
      &lt;/li&gt;
      &lt;li&gt;Update the lock file:

&lt;pre&gt;&lt;code&gt;poetry lock --no-update&lt;/code&gt;&lt;/pre&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;

  &lt;li&gt;
&lt;strong&gt;Install Dependencies:&lt;/strong&gt;

&lt;pre&gt;&lt;code&gt;poetry add redis^4.5.4 twilio^8.1.0 vocode==0.1.111 vonage^3.5.1 python-dotenv^1.0.0&lt;/code&gt;&lt;/pre&gt;
  &lt;/li&gt;

  &lt;li&gt;
&lt;strong&gt;Verify Installation:&lt;/strong&gt;

    &lt;ul&gt;
      &lt;li&gt;Create &lt;code&gt;main.py&lt;/code&gt; and add:

&lt;pre&gt;&lt;code&gt;print("Hello, GenAI")&lt;/code&gt;&lt;/pre&gt;
      &lt;/li&gt;
      &lt;li&gt;Run:

&lt;pre&gt;&lt;code&gt;poetry run python main.py&lt;/code&gt;&lt;/pre&gt;
      &lt;/li&gt;
      &lt;li&gt;You should see "Hello, GenAI" printed in the console.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;3. Configuring Environment Variables and Ngrok&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;
&lt;strong&gt;Create the &lt;code&gt;.env&lt;/code&gt; File:&lt;/strong&gt;

    &lt;ul&gt;
      &lt;li&gt;Create a &lt;code&gt;.env&lt;/code&gt; file in your project's root directory.&lt;/li&gt;
      &lt;li&gt;Add your credentials (replace placeholders with actual values):

&lt;pre&gt;&lt;code&gt;BASE_URL=
DEEPGRAM_API_KEY=
OPENAI_API_KEY=
AZURE_SPEECH_KEY=
AZURE_SPEECH_REGION=
TWILIO_ACCOUNT_SID=
TWILIO_AUTH_TOKEN=
TWILIO_FROM_NUMBER=&lt;/code&gt;&lt;/pre&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;

  &lt;li&gt;
&lt;strong&gt;Set Up Ngrok:&lt;/strong&gt;

    &lt;ul&gt;
      &lt;li&gt;Install Ngrok from &lt;a href="https://ngrok.com/download" rel="noopener noreferrer"&gt;https://ngrok.com/download&lt;/a&gt;.&lt;/li&gt;
      &lt;li&gt;Set up your Ngrok AuthToken from &lt;a href="https://dashboard.ngrok.com/get-started/your-authtoken" rel="noopener noreferrer"&gt;https://dashboard.ngrok.com/get-started/your-authtoken&lt;/a&gt;.&lt;/li&gt;
      &lt;li&gt;Run in a separate terminal:

&lt;pre&gt;&lt;code&gt;ngrok http 3000&lt;/code&gt;&lt;/pre&gt;
      &lt;/li&gt;
      &lt;li&gt;Copy the provided ngrok URL (e.g., &lt;code&gt;https://abcdef123456.ngrok.io&lt;/code&gt;) and paste it as your &lt;code&gt;BASE_URL&lt;/code&gt; in &lt;code&gt;.env&lt;/code&gt;, removing the &lt;code&gt;https://&lt;/code&gt; prefix and trailing slash.&lt;/li&gt;
      &lt;li&gt;Image of ngrok terminal output
        &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2Fbc7WCNd.png" alt="ngrok terminal output"&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;4. Setting Up the Telephony Server&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;
&lt;strong&gt;Copy the Server Code:&lt;/strong&gt;
    Get the code from this Gist: &lt;a href="https://gist.github.com/bajajcodes/5722cade50a9867b98b246a2cb30ced4" rel="noopener noreferrer"&gt;https://gist.github.com/bajajcodes/5722cade50a9867b98b246a2cb30ced4&lt;/a&gt; and paste it into &lt;code&gt;main.py&lt;/code&gt;.&lt;/li&gt;

  &lt;li&gt;
&lt;strong&gt;Activate Your Virtual Environment:&lt;/strong&gt;

&lt;pre&gt;&lt;code&gt;poetry shell&lt;/code&gt;&lt;/pre&gt;
  &lt;/li&gt;

  &lt;li&gt;
&lt;strong&gt;Run the Server:&lt;/strong&gt;

&lt;pre&gt;&lt;code&gt;poetry run python main.py&lt;/code&gt;&lt;/pre&gt;
  &lt;/li&gt;

  &lt;li&gt;
&lt;strong&gt;Start the FastAPI Server (Add to main.py):&lt;/strong&gt;

&lt;pre&gt;&lt;code&gt;import uvicorn

if __name__ == "__main__":
uvicorn.run(app, host="localhost", port=port)&lt;/code&gt;&lt;/pre&gt;
  &lt;/li&gt;

  &lt;li&gt;
&lt;strong&gt;Run the Script Again:&lt;/strong&gt;

&lt;pre&gt;&lt;code&gt;poetry run python main.py&lt;/code&gt;&lt;/pre&gt;
  &lt;/li&gt;

&lt;/ol&gt;

&lt;ul&gt;
  &lt;li&gt;Image of Uvicorn Server Output
    &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2F0ajDCfi.png" alt="Uvicorn Server Output"&gt;
  &lt;/li&gt;
  &lt;li&gt;Image of ngrok accessing localhost server
    &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FRvkrOQl.png" alt="ngrok accessing localhost server"&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;5. Creating the Outbound Call Script&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;
&lt;strong&gt;Set Up Redis:&lt;/strong&gt;

&lt;pre&gt;&lt;code&gt;docker run -dp 6379:6379 -it redis/redis-stack:latest&lt;/code&gt;&lt;/pre&gt;
  &lt;/li&gt;

  &lt;li&gt;
&lt;strong&gt;Create outbound_call.py:&lt;/strong&gt;

Copy the code from this Gist: &lt;a href="https://gist.github.com/bajajcodes/718b598b26e146c4b6bbc784c1d2b1c0" rel="noopener noreferrer"&gt;https://gist.github.com/bajajcodes/718b598b26e146c4b6bbc784c1d2b1c0&lt;/a&gt; and paste it into &lt;code&gt;outbound_call.py&lt;/code&gt;.&lt;/li&gt;

  &lt;li&gt;
&lt;strong&gt;Activate Your Virtual Environment:&lt;/strong&gt;

&lt;pre&gt;&lt;code&gt;poetry shell&lt;/code&gt;&lt;/pre&gt;
  &lt;/li&gt;

  &lt;li&gt;
&lt;strong&gt;Run the Script:&lt;/strong&gt;

&lt;pre&gt;&lt;code&gt;poetry run python outbound_call.py&lt;/code&gt;&lt;/pre&gt;
  &lt;/li&gt;

&lt;/ol&gt;

&lt;ul&gt;
  &lt;li&gt;Image of Script Console Output
    &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2F13bM79B.png" alt="Script Console Output"&gt;
  &lt;/li&gt;
  &lt;li&gt;Image of Server Logs
    &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FqclFgDy.png" alt="Server Logs"&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;6. Additional Notes and Troubleshooting&lt;/h2&gt;

&lt;ul&gt;
 &lt;li&gt;
&lt;strong&gt;Ngrok URL:&lt;/strong&gt; Ensure the &lt;code&gt;BASE_URL&lt;/code&gt; in &lt;code&gt;.env&lt;/code&gt; matches the ngrok URL.&lt;/li&gt;
 &lt;li&gt;
&lt;strong&gt;Endpoints:&lt;/strong&gt; Access your FastAPI app at the ngrok URL or your &lt;code&gt;BASE_URL&lt;/code&gt;. You can test endpoints like &lt;code&gt;/inbound_call&lt;/code&gt;, &lt;code&gt;/events&lt;/code&gt;, and &lt;code&gt;/recordings&lt;/code&gt; using &lt;code&gt;curl&lt;/code&gt; or a web browser.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;7. References&lt;/h2&gt;

&lt;ul&gt;
 &lt;li&gt;Vocode Telephony Server Documentation: &lt;a href="https://docs.vocode.dev/open-source/telephony" rel="noopener noreferrer"&gt;https://docs.vocode.dev/open-source/telephony&lt;/a&gt;
&lt;/li&gt;
 &lt;li&gt;Vocode Telephony Server Code: &lt;a href="https://github.com/vocodedev/vocode-python/tree/main/apps/telephony_app" rel="noopener noreferrer"&gt;https://github.com/vocodedev/vocode-python/tree/main/apps/telephony_app&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>genai</category>
      <category>ai</category>
      <category>vocode</category>
      <category>voiceai</category>
    </item>
    <item>
      <title>Mastering Jest Configuration for React TypeScript Projects with Vite: A Step-by-Step Guide</title>
      <dc:creator>Shubham Bajaj</dc:creator>
      <pubDate>Fri, 15 Dec 2023 18:27:34 +0000</pubDate>
      <link>https://forem.com/bajajcodes/mastering-jest-configuration-for-react-typescript-projects-with-vite-a-step-by-step-guide-4k4b</link>
      <guid>https://forem.com/bajajcodes/mastering-jest-configuration-for-react-typescript-projects-with-vite-a-step-by-step-guide-4k4b</guid>
      <description>&lt;h2&gt;
  
  
  1. First generate react typescript using vite
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm create vite@latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. Install dependancies
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm i jest @types/jest ts-jest &lt;span class="nt"&gt;--save-dev&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3. Exclude test files from typescript type checking for production
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Create tsconfig.prod.json and paste following contents into it.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;touch &lt;/span&gt;tsconfig.prod.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// tsconfig.prod.json&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;extends&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./tsconfig&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;exclude&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./src/__tests__/**&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./src/__mocks__/**&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./src/test-utils&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Exclude test files from typescript type checking when building for production, you don’t want a typescript error in your test file breaks your build in production.
&lt;/p&gt;
  —Nguyen Viet Hung, &lt;cite&gt;hung.dev&lt;/cite&gt;
&lt;/blockquote&gt;



&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;tsconfig.prod.json&lt;/code&gt; when building
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# package.json&lt;/span&gt;
&lt;span class="o"&gt;{&lt;/span&gt;
...,
&lt;span class="s2"&gt;"scripts"&lt;/span&gt;:&lt;span class="o"&gt;{&lt;/span&gt;
  ...,
  &lt;span class="s2"&gt;"build"&lt;/span&gt;: &lt;span class="s2"&gt;"NODE_ENV=production tsc -p tsconfig.prod.json &amp;amp;&amp;amp; vite build"&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;,
...
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4. Add &lt;code&gt;test&lt;/code&gt; script to &lt;code&gt;package.json&lt;/code&gt;
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// package.json&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="p"&gt;...,&lt;/span&gt;
&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;scripts&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:{&lt;/span&gt;
  &lt;span class="p"&gt;...,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;test&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;NODE_ENV=test jest&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  5. Write a simple test
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// src/App.test.tsx&lt;/span&gt;

&lt;span class="nf"&gt;describe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;App&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;it&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;should work as expected&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toBe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run the &lt;code&gt;npm run test&lt;/code&gt; 🤞, and first test case 😃 passed. 🚀&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;node &lt;span class="s1"&gt;'node_modules/.bin/jest'&lt;/span&gt; &lt;span class="s1"&gt;'/.../code/my-doc-test-app/src/App.test.tsx'&lt;/span&gt; &lt;span class="nt"&gt;-t&lt;/span&gt; &lt;span class="s1"&gt;'App'&lt;/span&gt;
 PASS  src/App.test.tsx
  App
    ✓ should work as expected &lt;span class="o"&gt;(&lt;/span&gt;1 ms&lt;span class="o"&gt;)&lt;/span&gt;

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        0.209 s
Ran all &lt;span class="nb"&gt;test &lt;/span&gt;suites matching /...&lt;span class="se"&gt;\/&lt;/span&gt;code&lt;span class="se"&gt;\/&lt;/span&gt;my-doc-test-app&lt;span class="se"&gt;\/&lt;/span&gt;src&lt;span class="se"&gt;\/&lt;/span&gt;App.test.tsx/i with tests matching &lt;span class="s2"&gt;"App"&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  6. Test the &lt;code&gt;App&lt;/code&gt; component
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// src/App.test.tsx&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;render&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@testing-library/react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./App&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;describe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;App&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;it&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;should work as expected&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run the &lt;code&gt;npm run test&lt;/code&gt; 🤞, and test failed. This error will show up.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;node &lt;span class="s1"&gt;'node_modules/.bin/jest'&lt;/span&gt; &lt;span class="s1"&gt;'/Users/satparkash/code/test-app/src/A
pp.test.tsx'&lt;/span&gt; &lt;span class="nt"&gt;-t&lt;/span&gt; &lt;span class="s1"&gt;'App'&lt;/span&gt;
 FAIL  src/App.test.tsx
  ● Test suite failed to run

    SyntaxError: /Users/satparkash/code/test-app/src/App.test.tsx: Support &lt;span class="k"&gt;for &lt;/span&gt;the experimental syntax &lt;span class="s1"&gt;'jsx'&lt;/span&gt; isn&lt;span class="s1"&gt;'t currently enabled (6:12):

      4 | describe('&lt;/span&gt;App&lt;span class="s1"&gt;', () =&amp;gt; {
      5 |   it('&lt;/span&gt;should work as expected&lt;span class="s1"&gt;', () =&amp;gt; {
    &amp;gt; 6 |     render(&amp;lt;App /&amp;gt;);
        |            ^
      7 |   });
      8 | });
      9 |

    Add @babel/preset-react (https://github.com/babel/babel/tree/main/packages/babel-preset-react) to the '&lt;/span&gt;presets&lt;span class="s1"&gt;' section of your Babel config to enable transformation.
    If you want to leave it as-is, add @babel/plugin-syntax-jsx (https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-jsx) to the '&lt;/span&gt;plugins&lt;span class="s1"&gt;' section to enable parsing.

    Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        0.278 s
Ran all test suites matching /\/Users\/satparkash\/code\/test-app\/src\/App.test.tsx/i with tests matching "App".

&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above ☝️ error message is indicating a syntax related to &lt;code&gt;JSX&lt;/code&gt; in test file.&lt;br&gt;
The error is saying that support for the syntax 'JSX' isn't currently enabled.&lt;/p&gt;

&lt;p&gt;To resolve the issue we need to make sure that the &lt;code&gt;JSX&lt;/code&gt; syntax is properly&lt;br&gt;
configured for project, and also the &lt;code&gt;jest&lt;/code&gt;. &lt;strong&gt;(Hint: Babel)&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  7. For JSX support, add babel presets and add .babelrc
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Firstly Install dependancies
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm i @babel/preset-env @babel/preset-react @babel/preset-typescript &lt;span class="nt"&gt;--save-dev&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Create &lt;code&gt;.babelrc&lt;/code&gt; file at project root, and paste following contents into it.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;touch&lt;/span&gt; .babelrc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//.babelrc&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;presets&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@babel/preset-env&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@babel/preset-react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;runtime&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;automatic&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;}],&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@babel/preset-typescript&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  8. Install testing library for react
&lt;/h2&gt;

&lt;p&gt;By Now previous error will be gone and you will get new error message.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;node &lt;span class="s1"&gt;'node_modules/.bin/jest'&lt;/span&gt; &lt;span class="s1"&gt;'/Users/satparkash/code/test-app/src
/App.test.tsx'&lt;/span&gt; &lt;span class="nt"&gt;-t&lt;/span&gt; &lt;span class="s1"&gt;'App'&lt;/span&gt;
 FAIL  src/App.test.tsx
  ● Test suite failed to run

    Cannot find module &lt;span class="s1"&gt;'@testing-library/react'&lt;/span&gt; from &lt;span class="s1"&gt;'src/App.test.tsx'&lt;/span&gt;

    &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; 1 | import &lt;span class="o"&gt;{&lt;/span&gt; render &lt;span class="o"&gt;}&lt;/span&gt; from &lt;span class="s1"&gt;'@testing-library/react'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        | ^
      2 | import App from &lt;span class="s1"&gt;'./App'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      3 |
      4 | describe&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'App'&lt;/span&gt;, &lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

      at Resolver._throwModNotFoundError &lt;span class="o"&gt;(&lt;/span&gt;node_modules/jest-resolve/build/resolver.js:427:11&lt;span class="o"&gt;)&lt;/span&gt;
      at Object.require &lt;span class="o"&gt;(&lt;/span&gt;src/App.test.tsx:1:1&lt;span class="o"&gt;)&lt;/span&gt;

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        0.231 s
Ran all &lt;span class="nb"&gt;test &lt;/span&gt;suites matching /&lt;span class="se"&gt;\/&lt;/span&gt;Users&lt;span class="se"&gt;\/&lt;/span&gt;satparkash&lt;span class="se"&gt;\/&lt;/span&gt;code&lt;span class="se"&gt;\/&lt;/span&gt;test-app&lt;span class="se"&gt;\/&lt;/span&gt;src&lt;span class="se"&gt;\/&lt;/span&gt;App.test.tsx/i with tests matching &lt;span class="s2"&gt;"App"&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Now, you have to add libraries which will allow you to make things happen (access VDOM, interacting …. etc), And those libraries are “@testing-library/dom”, “@testing-library/jest-dom”, “@testing-library/react” and “@testing-library/user-event”&lt;/p&gt;
  —Mhand
&lt;/blockquote&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm i @testing-library/dom @testing-library/jest-dom @testing-library/react @testing-library/user-event &lt;span class="nt"&gt;--save-dev&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now it's time to configure jest-environment. You will see another error message&lt;br&gt;
saying &lt;code&gt;Jest encountered an unexpected token&lt;/code&gt;, don't worry we are about to fix&lt;br&gt;
it.&lt;/p&gt;
&lt;h2&gt;
  
  
  9. Let's Configure Jest
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Firstly install following dependancies
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm i ts-node jest-environment-jsdom &lt;span class="nt"&gt;--save-dev&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Create a file &lt;code&gt;jest.config.ts&lt;/code&gt; at the root project, and paste following
contents into it.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;touch &lt;/span&gt;jest.config.ts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//jest.config.ts&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;rootDir&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;src&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;preset&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ts-jest&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;testEnvironment&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;jsdom&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;^.+&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s1"&gt;.tsx?$&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ts-jest&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="c1"&gt;// process `*.tsx` files with `ts-jest`&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;moduleNameMapper&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s1"&gt;.(gif|ttf|eot|svg|png)$&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;&amp;lt;rootDir&amp;gt;/config/jest/fileMock.ts&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;^.+&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s1"&gt;.(css|less|scss|sass)$&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;&amp;lt;rootDir&amp;gt;/config/jest/styleMock.ts&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;setupFilesAfterEnv&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./config/jest/setupTests.ts&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;moduleFileExtensions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="c1"&gt;// Place tsx and ts to beginning as suggestion from Jest team&lt;/span&gt;
    &lt;span class="c1"&gt;// https://jestjs.io/docs/configuration#modulefileextensions-arraystring&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;tsx&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ts&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;web.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;web.ts&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;web.tsx&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;json&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;web.jsx&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;jsx&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;node&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;modulePaths&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;&amp;lt;rootDir&amp;gt;/src&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Create &lt;code&gt;config/jest/styleMock.ts&lt;/code&gt;, &lt;code&gt;config/jest/fileMock.ts&lt;/code&gt; to mock css and
files.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// config/jest/styleMock.ts&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// config/jest/fileMock.ts&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt; &lt;span class="c1"&gt;//coment this if you ts-node to start complaining again&lt;/span&gt;
&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;test-file-stub&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Create &lt;code&gt;config/jest/setupTests.ts&lt;/code&gt;, a file that runs before each test.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//config/jest/setupTests.ts&lt;/span&gt;

&lt;span class="c1"&gt;// jest-dom adds custom jest matchers for asserting on DOM nodes.&lt;/span&gt;
&lt;span class="c1"&gt;// allows you to do things like:&lt;/span&gt;
&lt;span class="c1"&gt;// expect(element).toHaveTextContent(/react/i)&lt;/span&gt;
&lt;span class="c1"&gt;// learn more: https://github.com/testing-library/jest-dom&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@testing-library/jest-dom&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;blockquote&gt;
&lt;p&gt;INFO&lt;br&gt;
&lt;/p&gt;


&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="cm"&gt;/**
 *
 * If imported(inside setupTests.ts):
 * import '@testing-library/jest-dom/extend-expect'
 * then we are required to map it inside `jest.config.ts` like this:
 * 

 * // jest.config.ts
 * {
 * ...,
 * moduleNameMapper: {
 * ...,
 *     '@testing-library/jest-dom/extend-expect': '@testing-library/jest-dom',
 * }
 * }
 */&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By this moment, you can run the test successfully😎.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;node &lt;span class="s1"&gt;'node_modules/.bin/jest'&lt;/span&gt; &lt;span class="s1"&gt;'/Users/satparkash/code/test-app/src/App.test.tsx'&lt;/span&gt; &lt;span class="nt"&gt;-t&lt;/span&gt; &lt;span class="s1"&gt;'App'&lt;/span&gt;
 PASS  src/App.test.tsx
  App
    ✓ should work as expected &lt;span class="o"&gt;(&lt;/span&gt;12 ms&lt;span class="o"&gt;)&lt;/span&gt;

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        1.19 s
Ran all &lt;span class="nb"&gt;test &lt;/span&gt;suites matching /&lt;span class="se"&gt;\/&lt;/span&gt;Users&lt;span class="se"&gt;\/&lt;/span&gt;satparkash&lt;span class="se"&gt;\/&lt;/span&gt;code&lt;span class="se"&gt;\/&lt;/span&gt;test-app&lt;span class="se"&gt;\/&lt;/span&gt;src&lt;span class="se"&gt;\/&lt;/span&gt;App.test.tsx/i with tests matching &lt;span class="s2"&gt;"App"&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Happy testing 😀&lt;/p&gt;




&lt;h2&gt;
  
  
  10. For Snapsot Testing [optional]
&lt;/h2&gt;

&lt;p&gt;For snapshot testing add react-test-renderer&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm i react-test-renderer &lt;span class="nt"&gt;--save-dev&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;PS: I didnt' implemented snapshot testing 😄 Yet.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  11. For import.meta' meta-property is only allowed when the '--module' option is... [error TS1343]
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Error Message
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;error TS1343: The &lt;span class="s1"&gt;'import.meta'&lt;/span&gt; meta-property is only allowed when the &lt;span class="s1"&gt;'--module'&lt;/span&gt; option is &lt;span class="s1"&gt;'es2020'&lt;/span&gt;, &lt;span class="s1"&gt;'es2022'&lt;/span&gt;, &lt;span class="s1"&gt;'esnext'&lt;/span&gt;, &lt;span class="s1"&gt;'system'&lt;/span&gt;, &lt;span class="s1"&gt;'node16'&lt;/span&gt;, or &lt;span class="s1"&gt;'nodenext'&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt;

          .get&lt;span class="o"&gt;(&lt;/span&gt;import.meta.env.VITE_API_PATH + &lt;span class="s1"&gt;'/api/posts'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Install dependancy
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-D&lt;/span&gt; ts-jest-mock-import-meta
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Change the transform to mock &lt;code&gt;import.meta&lt;/code&gt; of vite
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// jest.config.ts&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="p"&gt;...,&lt;/span&gt;
    &lt;span class="na"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;^.+&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s1"&gt;.tsx?$&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
      &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ts-jest&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;diagnostics&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="na"&gt;ignoreCodes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1343&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="na"&gt;astTransformers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="na"&gt;before&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
              &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;node_modules/ts-jest-mock-import-meta&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
              &lt;span class="na"&gt;options&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="na"&gt;metaObjectReplacement&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                  &lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="c1"&gt;// Replicate as .env.local&lt;/span&gt;
                    &lt;span class="na"&gt;VITE_API_PATH&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;http://localhost:3001&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                  &lt;span class="p"&gt;},&lt;/span&gt;
                &lt;span class="p"&gt;},&lt;/span&gt;
              &lt;span class="p"&gt;},&lt;/span&gt;
            &lt;span class="p"&gt;},&lt;/span&gt;
          &lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  References
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://hung.dev/posts/jest-vite"&gt;Setup Jest with Vite (featuring SWC)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://maous.medium.com/setup-testing-environment-for-react-typescript-with-jest-1f5eb453aa2"&gt;Setup Testing Environment for React/TypeScript with Jest ! &lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/hannahadora/jest-testing-with-vite-and-react-typescript-4bap"&gt;Installing Jest for Testing in Your Vite-React TypeScript Project. A Step-by-Step Guide.&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://zaferayan.medium.com/how-to-setup-jest-and-react-testing-library-in-vite-project-2600f2d04bdd"&gt;How to setup Jest and React Testing Library in Vite project &lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://chat.openai.com/share/a9f98f2c-a707-4272-b788-32845fe4b395"&gt;ChatGPT&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/kulshekhar/ts-jest/issues/3888"&gt;The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>jest</category>
      <category>vite</category>
      <category>react</category>
      <category>testing</category>
    </item>
    <item>
      <title>Mastering JavaScript: Understanding TypeError vs ReferenceError and == vs ===</title>
      <dc:creator>Shubham Bajaj</dc:creator>
      <pubDate>Mon, 13 Feb 2023 08:00:49 +0000</pubDate>
      <link>https://forem.com/bajajcodes/mastering-javascript-understanding-typeerror-vs-referenceerror-and-vs--5h0l</link>
      <guid>https://forem.com/bajajcodes/mastering-javascript-understanding-typeerror-vs-referenceerror-and-vs--5h0l</guid>
      <description>&lt;p&gt;JavaScript is a powerful and flexible programming language, but it can be confusing for beginners. In this article, we will explore two common errors that developers face while coding in JavaScript: TypeError and ReferenceError, and how to avoid them. We will also take a deep dive into the difference between == and ===, two common comparison operators in JavaScript.&lt;/p&gt;

&lt;h2&gt;
  
  
  TypeError in JavaScript
&lt;/h2&gt;

&lt;p&gt;A TypeError in JavaScript occurs when you try to perform an operation on an object that is not of the correct type. For example, trying to access a property of an undefined object or calling a function that is not a function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
&lt;span class="c1"&gt;// TypeError: Cannot read property 'name' of undefined&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hello&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nf"&gt;a&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// TypeError: a is not a function&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To avoid TypeErrors, it is important to always check if an object is defined and of the correct type before trying to perform operations on it.&lt;/p&gt;

&lt;h2&gt;
  
  
  ReferenceError in JavaScript
&lt;/h2&gt;

&lt;p&gt;A ReferenceError in JavaScript occurs when you try to access a variable that has not been declared. This is often caused by typo mistakes or forgetting to declare the variable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// ReferenceError: b is not defined&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To avoid ReferenceErrors, it is important to declare all the variables you need before using them and to double-check for typo mistakes.&lt;/p&gt;

&lt;h2&gt;
  
  
  == vs === in JavaScript
&lt;/h2&gt;

&lt;p&gt;== and === are two comparison operators in JavaScript. The == operator compares values and returns true if they are equal, while the === operator compares both values and types and returns true only if both are equal.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;5&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It is important to use the === operator whenever possible, as it ensures that the comparison is both value and type-sensitive, avoiding unexpected results in your code.&lt;/p&gt;

&lt;p&gt;In conclusion, understanding TypeError, ReferenceError, and the difference between == and === are crucial concepts for writing high-quality, bug-free code in JavaScript. Always check the type and declaration of your variables and objects before performing operations on them, and use the === operator whenever possible. Happy coding!&lt;/p&gt;

</description>
      <category>discuss</category>
    </item>
    <item>
      <title>"A Beginner's Guide to Understanding Undefined, Functions, Console, and Console.log in JavaScript"</title>
      <dc:creator>Shubham Bajaj</dc:creator>
      <pubDate>Mon, 13 Feb 2023 07:42:31 +0000</pubDate>
      <link>https://forem.com/bajajcodes/a-beginners-guide-to-understanding-undefined-functions-console-and-consolelog-in-javascript-e68</link>
      <guid>https://forem.com/bajajcodes/a-beginners-guide-to-understanding-undefined-functions-console-and-consolelog-in-javascript-e68</guid>
      <description>&lt;h2&gt;
  
  
  Table Of Contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;What is Undefined in JavaScript?&lt;/li&gt;
&lt;li&gt;Why Does a Function When Called Returns Undefined?&lt;/li&gt;
&lt;li&gt;What is Console and Console.log in JavaScript?&lt;/li&gt;
&lt;li&gt;Why Does the Console Return Undefined on Executing the Log Method?&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What is Undefined in JavaScript?
&lt;/h2&gt;

&lt;p&gt;In JavaScript, undefined is a value that represents the absence of a value. It is a special value that indicates that a variable has been declared, but it has not been assigned a value.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Output: undefined&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the variable a is declared, but it has not been assigned a value, so it is considered to have the value undefined.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Does a Function When Called Returns Undefined?
&lt;/h2&gt;

&lt;p&gt;In JavaScript, a function is a block of code that is designed to perform a specific task. When you call a function, it executes the code inside it, and then returns a value. If a function doesn't have a return statement, or if the return statement doesn't have a value, then the function returns undefined.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;hello&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello, World!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;hello&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Output: "Hello, World!"&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;hello&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// Output: "Hello, World!" undefined&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the hello function doesn't have a return statement, so it returns undefined.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Console and Console.log in JavaScript?
&lt;/h2&gt;

&lt;p&gt;The console is a tool used by developers to debug their code. It is part of the JavaScript development environment and can be accessed in the browser's developer tools. The console.log method is used to log information to the console.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Output: 10&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the console.log method is used to log the value of the variable a, which is 10, to the console.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Does the Console Return Undefined on Executing the Log Method?
&lt;/h2&gt;

&lt;p&gt;The console.log method displays undefined when you try to log a value that doesn't have a defined value.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Output: undefined&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the variable a is declared but not initialized, meaning it doesn't have a value. When we try to log a to the console, it shows undefined because that's the value of the variable.&lt;/p&gt;

&lt;p&gt;In conclusion, understanding the concepts of undefined, functions, console, and console.log is important for debugging your code and making sure it works as intended.&lt;/p&gt;

</description>
      <category>fullstack</category>
      <category>career</category>
      <category>codenewbie</category>
      <category>softwaredevelopment</category>
    </item>
  </channel>
</rss>
