<?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>DEV Community: Juan de Tomaso</title>
    <description>The latest articles on DEV Community by Juan de Tomaso (@juan_deto).</description>
    <link>https://dev.to/juan_deto</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%2F409137%2F701bd7a2-2315-4307-837a-93d88d9e2b30.jpg</url>
      <title>DEV Community: Juan de Tomaso</title>
      <link>https://dev.to/juan_deto</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/juan_deto"/>
    <language>en</language>
    <item>
      <title>Configure Vitest, MSW and Playwright in a React project with Vite and TS - Part 3</title>
      <dc:creator>Juan de Tomaso</dc:creator>
      <pubDate>Thu, 10 Oct 2024 19:15:12 +0000</pubDate>
      <link>https://dev.to/juan_deto/configure-vitest-msw-and-playwright-in-a-react-project-with-vite-and-ts-part-3-32pe</link>
      <guid>https://dev.to/juan_deto/configure-vitest-msw-and-playwright-in-a-react-project-with-vite-and-ts-part-3-32pe</guid>
      <description>&lt;p&gt;Playwright is a framework-agnostic end-to-end testing (also known as E2E, or integration testing) tool for web apps. Playwright has great developer experience and makes writing good and resilient to changes tests straightforward.&lt;/p&gt;




&lt;h3&gt;
  
  
  1. Install Playwright
&lt;/h3&gt;

&lt;p&gt;To set up Playwright, run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm init playwright@latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You'll be guided through a setup wizard in your terminal. When prompted with &lt;strong&gt;"Where to put your end-to-end tests?"&lt;/strong&gt;, you can set it to &lt;code&gt;src/tests&lt;/code&gt; (as recommended in earlier tutorials).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsapegin.me%2Fimages%2Fplaywright-wizard.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsapegin.me%2Fimages%2Fplaywright-wizard.webp" alt="terminal prompt" width="800" height="157"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Add Scripts to &lt;code&gt;package.json&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;In your &lt;code&gt;package.json&lt;/code&gt;, add the following two scripts for running Playwright tests:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F59adfy710j8d1vqsbvv8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F59adfy710j8d1vqsbvv8.png" alt="package.json config" width="661" height="233"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This allows you to run the tests in both development and CI environments.&lt;/p&gt;

&lt;h4&gt;
  
  
  Playwright Configuration
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;playwright.config.ts&lt;/code&gt; file should be configured as follows:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw2x181did0j4fkmskaue.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw2x181did0j4fkmskaue.png" alt="playwright.config.ts file" width="800" height="681"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Key Changes in the Configuration:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;use.baseURL&lt;/code&gt;&lt;/strong&gt;: This sets the base URL of your development server, so you don’t have to write it in every test.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;webServer&lt;/code&gt;&lt;/strong&gt;: This block describes how to start your development server. It will reuse an already-running server unless you are in a CI environment.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;testDir&lt;/code&gt;&lt;/strong&gt;: The directory where Playwright should look for your E2E tests (in this case, &lt;code&gt;src/tests/e2e&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. Write an E2E Test
&lt;/h3&gt;

&lt;p&gt;Now you can write an E2E test for a flow in your app. Here’s an example Playwright test:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fssxoaov6ncaxylgbxdps.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fssxoaov6ncaxylgbxdps.png" alt="e2e test" width="692" height="889"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Check how Playwright has it's own way of intercepting network calls.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Running the Test
&lt;/h3&gt;

&lt;p&gt;To run the E2E test, use the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run test:e2e:ci
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will execute the test in CI mode, which is useful for automated pipelines.&lt;/p&gt;




&lt;h3&gt;
  
  
  EXTRA
&lt;/h3&gt;

&lt;p&gt;More often than you'd expect, you’ll need to mock query responses to test different scenarios—not necessarily for development purposes. For example, if the backend isn't ready yet and you need to proceed with a screen but are blocked, setting up MSW in the browser allows you to mock responses and keep moving forward.&lt;/p&gt;

&lt;p&gt;If you’ve followed the tutorial up to this point, MSW is already set up for testing in a Node.js environment. Now, we’ll configure MSW as a service worker to intercept queries in the browser. You might wonder why this is necessary if we already have Playwright. While Playwright is more focused on automating tests, think of MSW in this context as a development tool for quick testing.&lt;/p&gt;

&lt;p&gt;Let’s configure it:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Configure MSW for Browser Testing
&lt;/h3&gt;

&lt;p&gt;So far, MSW has been used to mock API responses in a Node.js environment. Now, let’s set it up for the browser.&lt;/p&gt;

&lt;p&gt;Create a new JavaScript module to register the MSW service worker for browser-based tests:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fktw65f7vvpwls2qc0qty.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fktw65f7vvpwls2qc0qty.png" alt="Image description" width="561" height="115"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Register the Worker in Development Mode
&lt;/h3&gt;

&lt;p&gt;To start the MSW worker when the app is running in development mode, add the following to your app’s root module (e.g., &lt;code&gt;src/main.tsx&lt;/code&gt;):&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftaa6yyijuww0dxhi5ry0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftaa6yyijuww0dxhi5ry0.png" alt="Image description" width="800" height="487"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Make sure to set the &lt;code&gt;VITE_API_MOCK&lt;/code&gt; environment variable in your &lt;code&gt;.env&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;VITE_API_MOCK="true"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;IMPORTANT:&lt;/strong&gt; The MSW worker and the Playwright worker can interfere with each other, so make sure to disable &lt;code&gt;VITE_API_MOCK&lt;/code&gt; when running end-to-end (E2E).&lt;/p&gt;

</description>
      <category>testing</category>
      <category>react</category>
      <category>javascript</category>
      <category>vite</category>
    </item>
    <item>
      <title>Configure Vitest, MSW and Playwright in a React project with Vite and TS - Part 2</title>
      <dc:creator>Juan de Tomaso</dc:creator>
      <pubDate>Thu, 10 Oct 2024 19:14:58 +0000</pubDate>
      <link>https://dev.to/juan_deto/configure-vitest-msw-and-playwright-in-a-react-project-with-vite-and-ts-part-2-553</link>
      <guid>https://dev.to/juan_deto/configure-vitest-msw-and-playwright-in-a-react-project-with-vite-and-ts-part-2-553</guid>
      <description>&lt;p&gt;MSW is a tool that allows you to intercept API calls and modify their responses. This helps you test your app in more realistic scenarios, with different responses.&lt;/p&gt;

&lt;p&gt;From a high-level view, MSW lets us intercept API calls in two scenarios:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;In the browser&lt;/strong&gt;: This allows you to mock API responses while you're developing the app, making it easier to test different responses as you write your code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;In a Node.js environment&lt;/strong&gt;: This is typically the case when running tests, such as with Vitest.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In this section, we'll configure MSW for the second scenario, to mock API calls in a Node.js environment during testing.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Step 1
&lt;/h3&gt;

&lt;p&gt;Install MSW as a development dependency and initialize it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install msw --save-dev
npx msw init ./public
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Setup Mock Server&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Next, under you /tests/&lt;strong&gt;mock&lt;/strong&gt; folder create a mock server that runs in a Node environment for use in your tests:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2c2g4il89q5kmizczznd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2c2g4il89q5kmizczznd.png" alt="mock server" width="380" height="79"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Update the Test Setup
&lt;/h3&gt;

&lt;p&gt;In your test setup file, configure the mock server to start and stop during the testing lifecycle:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd0o0zvsdxythibd7fgwm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd0o0zvsdxythibd7fgwm.png" alt="setup server cycles" width="577" height="485"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This configuration ensures that MSW is properly set up, cleaned up after each test, and the handlers are reset to maintain test isolation.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Setting up Handlers
&lt;/h3&gt;

&lt;p&gt;Next, under your /tests/&lt;strong&gt;mocks&lt;/strong&gt; folder setup your handlers. MSW provides handlers for different HTTP methods, like &lt;code&gt;GET&lt;/code&gt;, &lt;code&gt;POST&lt;/code&gt;, etc. Here's how you can mock the &lt;code&gt;GET&lt;/code&gt; request for our API:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu84qoaj9iknd4qu0n2ys.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu84qoaj9iknd4qu0n2ys.png" alt="handlers file" width="665" height="218"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;and then you set those handlers in your server:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fupum2lcavbdvzjt3sul5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fupum2lcavbdvzjt3sul5.png" alt="mock server updated" width="561" height="115"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  6. Writing Tests
&lt;/h3&gt;

&lt;p&gt;Here’s how you can write tests that use the mocked server and handlers. In ItemList.test.tsx:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7j3ph2hzyz9bp3h9xcho.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7j3ph2hzyz9bp3h9xcho.png" alt="test file" width="747" height="794"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Check out that to query the list container I set a &lt;code&gt;data-testid="list"&lt;/code&gt;in the container element of that component.&lt;/p&gt;




&lt;p&gt;In this example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We mock the API's &lt;code&gt;GET&lt;/code&gt; response using MSW.&lt;/li&gt;
&lt;li&gt;We handle both successful and failed API requests.&lt;/li&gt;
&lt;li&gt;We test that the UI displays the correct information or error message based on the response.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let me know if you need any further improvements or explanations!&lt;/p&gt;

</description>
      <category>testing</category>
      <category>react</category>
      <category>api</category>
      <category>vite</category>
    </item>
    <item>
      <title>Configure Vitest, MSW and Playwright in a React project with Vite and TS</title>
      <dc:creator>Juan de Tomaso</dc:creator>
      <pubDate>Thu, 10 Oct 2024 19:14:38 +0000</pubDate>
      <link>https://dev.to/juan_deto/configure-vitest-msw-and-playwright-in-a-react-project-with-vite-and-ts-1d92</link>
      <guid>https://dev.to/juan_deto/configure-vitest-msw-and-playwright-in-a-react-project-with-vite-and-ts-1d92</guid>
      <description>&lt;p&gt;Hi, web traveler! If you're here, it's probably because you understand the importance of good testing—or maybe you're just tired of the QA team pointing out issues. Either way, you're in the right place. This guide will help you configure and integrate tools that cover all the angles of testing your app.&lt;/p&gt;

&lt;p&gt;Just a quick reminder of what this tools are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Vitest&lt;/strong&gt;: For unit testing. If you've used Jest, this tool is quite similar but powered by the Vite engine.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;MSW&lt;/strong&gt;(Mock Service Worker): A tool that intercepts API calls and changes their response, so you can test different scenarios in your app without relying on real API endpoints.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Playwirght&lt;/strong&gt;: For end-to-end testing.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For this guide, we'll configure a simple React app with Vite. The app will query the public API of the Art Institute of Chicago, display the items in cards, and, when a user clicks on a card, navigate to a detailed view. If you're curious about the API, check it out &lt;a href="https://api.artic.edu/docs/#quick-start" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can clone the basic code to start this guide &lt;a href="https://github.com/juandeto/vitest-msw-playwright-config/tree/2b5a68fb4ff5337b01e3d75d5898fac4ccd5178f" rel="noopener noreferrer"&gt;in this repo&lt;/a&gt;. Here is a snapshot:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fit3t6hh99dpuy5if7zgz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fit3t6hh99dpuy5if7zgz.png" alt="snapshot of the app" width="800" height="448"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Vitest
&lt;/h2&gt;

&lt;p&gt;We'll start by configuring Vitest. If you’ve set up your app with Vite, you’ll probably want to use Vitest since it has a similar API to Jest but is optimized for the Vite environment. Let’s go step-by-step through the configuration.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Install packages
&lt;/h3&gt;

&lt;p&gt;First, install these packages as dev dependencies:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install -D @testing-library/react vitest jsdom @types/testing-library__jest-dom @testing-library/user-event
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is what you have installed:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;@testing-library/react: classic library build on top of the DOM Testing LIbrary to work with React components --&amp;gt; it lets you render and query React Components&lt;/li&gt;
&lt;li&gt;vitest: test runner --&amp;gt; it runs your tests&lt;/li&gt;
&lt;li&gt;jsdom: acts as a lightweight browser, creating an environment that simulates the DOM so you can test DOM-related behavior&lt;/li&gt;
&lt;li&gt;@types/testing-library__jest-dom: adds typing&lt;/li&gt;
&lt;li&gt;@testing-library/user-event: is partner of  @testing-library/react: and adds simulation of user interactions with browser&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. Configure Vite to handle tests with Vitest
&lt;/h3&gt;

&lt;p&gt;Next, modify your &lt;code&gt;vite.config.ts&lt;/code&gt; like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F80ry0vnlkdn8umoajlmc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F80ry0vnlkdn8umoajlmc.png" alt="vite config file" width="800" height="444"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Setup files
&lt;/h3&gt;

&lt;p&gt;Create the setup file we specified in &lt;code&gt;vite.config.ts&lt;/code&gt;. Inside &lt;code&gt;src&lt;/code&gt;, create &lt;code&gt;tests&lt;/code&gt; folder, and inside that, create &lt;code&gt;Setup.ts&lt;/code&gt; with the following basic setup:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { afterEach } from 'vitest';
import { cleanup } from '@testing-library/react';
import '@testing-library/jest-dom';

afterEach(() =&amp;gt; {
  cleanup();
});

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

&lt;/div&gt;



&lt;p&gt;Now, update your &lt;code&gt;tsconfig.json&lt;/code&gt; to include Vitest types:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "compilerOptions": {
    ...
    "types": ["vitest/globals"] 
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and don't forget to include the scripts in &lt;code&gt;package.json&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
 "scripts": {
    ...
    "test": "vitest",
    "test:watch": "vitest --watch"
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. Utils
&lt;/h3&gt;

&lt;p&gt;This is an extra step, but it’s super helpful to create a utility file for your tests. Inside the &lt;code&gt;tests&lt;/code&gt; folder, create a &lt;code&gt;TestUtils.tsx&lt;/code&gt; file:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F94nb09mikla0z3oce3yl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F94nb09mikla0z3oce3yl.png" alt="utils file" width="679" height="541"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Explanation:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The &lt;code&gt;Wrapper&lt;/code&gt;  function wraps your components in a &lt;code&gt;BrowserRouter&lt;/code&gt;. You can extend this by adding other providers like &lt;code&gt;QueryClientProvider&lt;/code&gt; or &lt;code&gt;IntlProvider&lt;/code&gt; as needed.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;customRender&lt;/code&gt; provides this wrapper to the &lt;code&gt;render&lt;/code&gt; function, and you can pass additional options as required.&lt;/li&gt;
&lt;li&gt;You export the necessary utilities from &lt;code&gt;@testing-library/react&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;setup&lt;/code&gt; function simplifies test setup by providing access to &lt;code&gt;userEvent&lt;/code&gt; and the custom render function.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  5. Testing.
&lt;/h3&gt;

&lt;p&gt;Finally, let’s test our configuration with a basic test in CopyrightWarning.test.tsx`. For examplee:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fus62lkxohkui023mt2f9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fus62lkxohkui023mt2f9.png" alt="testing with vitest" width="800" height="280"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This should provide a solid guide for integrating Vitest into your project. Next steps will involve configuring MSW and Playwright for complete test coverage. Stay tuned!&lt;/p&gt;

</description>
      <category>testing</category>
      <category>react</category>
      <category>tutorial</category>
      <category>vite</category>
    </item>
    <item>
      <title>Pollux - Text Assistant</title>
      <dc:creator>Juan de Tomaso</dc:creator>
      <pubDate>Tue, 04 Apr 2023 20:30:58 +0000</pubDate>
      <link>https://dev.to/juan_deto/pollux-text-assistan-3d96</link>
      <guid>https://dev.to/juan_deto/pollux-text-assistan-3d96</guid>
      <description>&lt;p&gt;Yes, I know, everywhere you look, there's a new magical thing going on with AI. But hey, it's okay. Two years ago, it was the same with crypto, but let's be honest, there weren't a lot of practical approaches as with AI and the GPT fever.&lt;/p&gt;

&lt;p&gt;Having said that, and with my consciousness haunted by FOMO and excitement, I have created this Chrome extension. It's called Pollux and is very practical and easy to use. The API was built in python fastAPI framework and deployed on a DigitalOcean machine. &lt;a href="https://chrome.google.com/webstore/detail/pollux/pfnjnoljecfpnjenjijncmdgmpmhnfhb"&gt;Here is the link to install it.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here are some interesting use cases:&lt;/p&gt;

&lt;p&gt;Use case 1: Suppose you are reading an article on any subject you like (news, blogs, newsletters, etc.) and you come across a paragraph you don't understand or a complex concept. You select it, right-click on the Pollux extension, and choose to explain the selected text as if you were 5 or 12 years old. You can even translate the explanation to other languages.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/M7oKhRadThY"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Use case 2: You select all the text of an article and make a summary in 5 bullet points, 3 tweets, etc. You can choose the format, language, and style.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/kS5v0B1k0X4?start=1"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;So, that's it. I hope you find this useful. It will probably become obsolete in a few days given how fast things are changing, but it was fun anyway.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Scopes in Javascript</title>
      <dc:creator>Juan de Tomaso</dc:creator>
      <pubDate>Sun, 05 Jul 2020 23:27:26 +0000</pubDate>
      <link>https://dev.to/juan_deto/scopes-in-javascript-5eo3</link>
      <guid>https://dev.to/juan_deto/scopes-in-javascript-5eo3</guid>
      <description>&lt;p&gt;In this post I want to explore the scopes in Javascript making a parallelism between Javascript and the principles of federalism in political science. &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FOovBkT0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ih616mzesfsy71achg1w.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FOovBkT0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ih616mzesfsy71achg1w.jpeg" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Let's say that the scope of variables are defined in a similar way to how a jurisdiction works in a federal system such as the one in Argentina or the United States: the global sphere (let's say the National State) sanctions laws that rule over all the sub-national states. Furthermore, the sub-national states dictate laws that rule over their territory, and so on, the counties or interior departments sanction laws that rule over their jurisdictions. &lt;br&gt;
Hence, the scope of the laws rules from top to bottom (National -&amp;gt; State -&amp;gt; County) and not the other way around. A county regulations has no authority at the state level, and a state regulation has no authority at the national level.&lt;/p&gt;

&lt;p&gt;The scope of variables in Javascript works the same way: a bind defined at the most global level has “jurisdiction” over the whole program. And so, a bind declared in a function has no global reach. It only has “jurisdiction” within the scope of the function in which it was defined and in functions nested within it. A variable defined in a nested function within another function only has jurisdiction in the scope of the nested function where it was defined, but has no reference in external functions or scopes, just like a county regulation has no authority at the state level. &lt;/p&gt;

&lt;p&gt;Finally, it is important to note that the parallelism only occurs when the variables are defined with let or const words. When the variables are defined with the word var it is necessary to look for another scenery because they are visible throughout the whole program, no matter where exactly they are defined.&lt;/p&gt;

&lt;p&gt;Hope you find it intresting and useful.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>My first web!😭</title>
      <dc:creator>Juan de Tomaso</dc:creator>
      <pubDate>Tue, 16 Jun 2020 03:23:15 +0000</pubDate>
      <link>https://dev.to/juan_deto/my-first-web-3i49</link>
      <guid>https://dev.to/juan_deto/my-first-web-3i49</guid>
      <description>&lt;p&gt;This is my first web. Its a simple portfolio of a photographer.&lt;/p&gt;

&lt;p&gt;I started with html css and javascript 4 months ago. I was very influent by Jen Simmons design aproach and the Bauhaus.&lt;/p&gt;

&lt;p&gt;Hope you enjoy it!&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.angelesmorgan.com"&gt;www.angelesmorgan.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>css</category>
    </item>
  </channel>
</rss>
