{"id":1562,"date":"2026-06-25T06:06:01","date_gmt":"2026-06-25T06:06:01","guid":{"rendered":"https:\/\/razvanvancea.ro\/blog\/?p=1562"},"modified":"2026-06-25T06:18:48","modified_gmt":"2026-06-25T06:18:48","slug":"unit-testing-in-javascript-getting-started-with-vitest-and-jsdom","status":"publish","type":"post","link":"https:\/\/razvanvancea.ro\/blog\/2026\/06\/25\/unit-testing-in-javascript-getting-started-with-vitest-and-jsdom\/","title":{"rendered":"Unit Testing in JavaScript: Getting started with Vitest"},"content":{"rendered":"<div id=\"bsf_rt_marker\"><\/div>\t\t<div data-elementor-type=\"wp-post\" data-elementor-id=\"1562\" class=\"elementor elementor-1562\">\n\t\t\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-a532db3 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"a532db3\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-05d6cb9\" data-id=\"05d6cb9\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-14fc687 elementor-widget elementor-widget-text-editor\" data-id=\"14fc687\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p class=\"PDq2pG_selectionAnchorContainer\" data-start=\"120\" data-end=\"299\">Unit testing is one of the easiest ways to make your JavaScript code more reliable. A unit test checks a small piece of code in isolation and confirms that it behaves as expected.<\/p><p data-start=\"301\" data-end=\"445\">In this article, we will set up a very simple testing stack using <a href=\"https:\/\/github.com\/vitest-dev\/vitest\" target=\"_blank\" rel=\"noopener\"><strong data-start=\"367\" data-end=\"377\">Vitest<\/strong><\/a> then write our first unit tests for a basic application.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-200aa2f elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"200aa2f\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-8460e52\" data-id=\"8460e52\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-9a2c134 elementor-widget elementor-widget-heading\" data-id=\"9a2c134\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">Why Unit Testing?<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-3688cc5 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"3688cc5\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-2c70060\" data-id=\"2c70060\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-f302ec5 elementor-widget elementor-widget-text-editor\" data-id=\"f302ec5\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p class=\"PDq2pG_selectionAnchorContainer\" data-start=\"469\" data-end=\"552\">When building a website, even a simple one, you usually have small pieces of logic:<\/p><ul data-start=\"554\" data-end=\"679\"><li data-section-id=\"1m2bbs\" data-start=\"554\" data-end=\"574\">calculating totals<\/li><li data-section-id=\"16or5sb\" data-start=\"575\" data-end=\"598\">validating form input<\/li><li data-section-id=\"189lb8d\" data-start=\"599\" data-end=\"626\">changing text on the page<\/li><li data-section-id=\"bq7aft\" data-start=\"627\" data-end=\"654\">reacting to button clicks<\/li><li data-section-id=\"13nve98\" data-start=\"655\" data-end=\"679\">updating HTML elements<\/li><\/ul><p data-start=\"681\" data-end=\"779\">Unit tests help you make sure these small pieces continue to work when you change your code later.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-ec616a9 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"ec616a9\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-fc7938b\" data-id=\"fc7938b\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-c1095ed elementor-widget elementor-widget-heading\" data-id=\"c1095ed\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">The tech stack<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-cf9c242 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"cf9c242\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-cefe7c9\" data-id=\"cefe7c9\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-2b96f7c elementor-widget elementor-widget-text-editor\" data-id=\"2b96f7c\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p class=\"PDq2pG_selectionAnchorContainer\" data-start=\"803\" data-end=\"831\">For this setup, we will use:<\/p><ul data-start=\"833\" data-end=\"938\"><li data-section-id=\"1q20f43\" data-start=\"833\" data-end=\"882\"><strong data-start=\"835\" data-end=\"845\">Vitest<\/strong>: a fast JavaScript testing framework<\/li><li data-section-id=\"1q20f43\" data-start=\"833\" data-end=\"882\"><strong data-start=\"885\" data-end=\"894\">jsdom<\/strong>: a browser-like DOM environment for Node.js<\/li><\/ul><p data-start=\"940\" data-end=\"1100\">Vitest runs our tests. jsdom gives us access to browser-like objects such as <code data-start=\"1017\" data-end=\"1027\">document<\/code>, <code data-start=\"1029\" data-end=\"1037\">window<\/code>, and HTML elements while running tests outside a real browser.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-dfedbcd elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"dfedbcd\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-b84cd5c\" data-id=\"b84cd5c\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-91e4740 elementor-widget elementor-widget-heading\" data-id=\"91e4740\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">Installing packages<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-affd4b4 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"affd4b4\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-eb86a30\" data-id=\"eb86a30\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-28fd094 elementor-widget elementor-widget-text-editor\" data-id=\"28fd094\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>First, install the dependencies:<\/p><pre><strong><span class=\"\u037cl\">npm<\/span> install <span class=\"\u037cn\">-D<\/span> vitest jsdom<\/strong><\/pre>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-56a3619 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"56a3619\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-6c8fd9d\" data-id=\"6c8fd9d\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-3353f09 elementor-widget elementor-widget-text-editor\" data-id=\"3353f09\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Then update your packages.json<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-7881f25 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"7881f25\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-70c5538\" data-id=\"70c5538\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-2b6d34a elementor-widget elementor-widget-image\" data-id=\"2b6d34a\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<img fetchpriority=\"high\" decoding=\"async\" width=\"640\" height=\"741\" src=\"https:\/\/razvanvancea.ro\/blog\/wp-content\/uploads\/2026\/06\/Screenshot-2026-06-25-at-09.02.59-885x1024.png\" class=\"attachment-large size-large wp-image-1564\" alt=\"vitest-package\" srcset=\"https:\/\/razvanvancea.ro\/blog\/wp-content\/uploads\/2026\/06\/Screenshot-2026-06-25-at-09.02.59-885x1024.png 885w, https:\/\/razvanvancea.ro\/blog\/wp-content\/uploads\/2026\/06\/Screenshot-2026-06-25-at-09.02.59-259x300.png 259w, https:\/\/razvanvancea.ro\/blog\/wp-content\/uploads\/2026\/06\/Screenshot-2026-06-25-at-09.02.59-768x889.png 768w, https:\/\/razvanvancea.ro\/blog\/wp-content\/uploads\/2026\/06\/Screenshot-2026-06-25-at-09.02.59-300x347.png 300w, https:\/\/razvanvancea.ro\/blog\/wp-content\/uploads\/2026\/06\/Screenshot-2026-06-25-at-09.02.59-850x984.png 850w, https:\/\/razvanvancea.ro\/blog\/wp-content\/uploads\/2026\/06\/Screenshot-2026-06-25-at-09.02.59-21x24.png 21w, https:\/\/razvanvancea.ro\/blog\/wp-content\/uploads\/2026\/06\/Screenshot-2026-06-25-at-09.02.59-31x36.png 31w, https:\/\/razvanvancea.ro\/blog\/wp-content\/uploads\/2026\/06\/Screenshot-2026-06-25-at-09.02.59-41x48.png 41w, https:\/\/razvanvancea.ro\/blog\/wp-content\/uploads\/2026\/06\/Screenshot-2026-06-25-at-09.02.59.png 942w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/>\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-f75b2b7 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"f75b2b7\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-6a51adb\" data-id=\"6a51adb\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-1054bfe elementor-widget elementor-widget-text-editor\" data-id=\"1054bfe\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<pre>Now you can run your test with<br \/><br \/><strong>npm test<\/strong><\/pre>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-7ab09e4 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"7ab09e4\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-1ae3442\" data-id=\"1ae3442\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-4330d1a elementor-widget elementor-widget-heading\" data-id=\"4330d1a\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">Testing a function<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-1ee3dcf elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"1ee3dcf\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-82891c1\" data-id=\"82891c1\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-752ab01 elementor-widget elementor-widget-text-editor\" data-id=\"752ab01\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Let\u2019s start with a pure JavaScript function. A pure function is easy to test because it does not depend on the browser, HTML, or external state.<\/p><p>Create a file called <em>cart.js<\/em><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-7b5ed56 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"7b5ed56\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-8b5950f\" data-id=\"8b5950f\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-aec08c7 elementor-widget elementor-widget-image\" data-id=\"aec08c7\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" width=\"640\" height=\"122\" src=\"https:\/\/razvanvancea.ro\/blog\/wp-content\/uploads\/2026\/06\/Screenshot-2026-06-25-at-09.07.55.png\" class=\"attachment-large size-large wp-image-1566\" alt=\"cart-vitest\" srcset=\"https:\/\/razvanvancea.ro\/blog\/wp-content\/uploads\/2026\/06\/Screenshot-2026-06-25-at-09.07.55.png 768w, https:\/\/razvanvancea.ro\/blog\/wp-content\/uploads\/2026\/06\/Screenshot-2026-06-25-at-09.07.55-300x57.png 300w, https:\/\/razvanvancea.ro\/blog\/wp-content\/uploads\/2026\/06\/Screenshot-2026-06-25-at-09.07.55-24x5.png 24w, https:\/\/razvanvancea.ro\/blog\/wp-content\/uploads\/2026\/06\/Screenshot-2026-06-25-at-09.07.55-36x7.png 36w, https:\/\/razvanvancea.ro\/blog\/wp-content\/uploads\/2026\/06\/Screenshot-2026-06-25-at-09.07.55-48x9.png 48w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/>\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-f9a2140 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"f9a2140\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-404b457\" data-id=\"404b457\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-e9f2161 elementor-widget elementor-widget-text-editor\" data-id=\"e9f2161\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Now create a test file called <em>cart.spec.js<\/em><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-fa25dee elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"fa25dee\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-933ad38\" data-id=\"933ad38\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-6cda641 elementor-widget elementor-widget-image\" data-id=\"6cda641\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" width=\"640\" height=\"178\" src=\"https:\/\/razvanvancea.ro\/blog\/wp-content\/uploads\/2026\/06\/Screenshot-2026-06-25-at-09.09.42.png\" class=\"attachment-large size-large wp-image-1570\" alt=\"\" srcset=\"https:\/\/razvanvancea.ro\/blog\/wp-content\/uploads\/2026\/06\/Screenshot-2026-06-25-at-09.09.42.png 862w, https:\/\/razvanvancea.ro\/blog\/wp-content\/uploads\/2026\/06\/Screenshot-2026-06-25-at-09.09.42-300x84.png 300w, https:\/\/razvanvancea.ro\/blog\/wp-content\/uploads\/2026\/06\/Screenshot-2026-06-25-at-09.09.42-768x214.png 768w, https:\/\/razvanvancea.ro\/blog\/wp-content\/uploads\/2026\/06\/Screenshot-2026-06-25-at-09.09.42-850x237.png 850w, https:\/\/razvanvancea.ro\/blog\/wp-content\/uploads\/2026\/06\/Screenshot-2026-06-25-at-09.09.42-24x7.png 24w, https:\/\/razvanvancea.ro\/blog\/wp-content\/uploads\/2026\/06\/Screenshot-2026-06-25-at-09.09.42-36x10.png 36w, https:\/\/razvanvancea.ro\/blog\/wp-content\/uploads\/2026\/06\/Screenshot-2026-06-25-at-09.09.42-48x13.png 48w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/>\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-093584b elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"093584b\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-78cc8b3\" data-id=\"78cc8b3\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-d3bce36 elementor-widget elementor-widget-text-editor\" data-id=\"d3bce36\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>This test checks that when the price is <code data-start=\"2054\" data-end=\"2058\">50<\/code> and the quantity is <code data-start=\"2079\" data-end=\"2082\">3<\/code>, the total is <code data-start=\"2097\" data-end=\"2102\">150<\/code>.<br \/><br \/>Run the test<\/p><pre><strong>npm test<\/strong><\/pre>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-190bbc6 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"190bbc6\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-140a27a\" data-id=\"140a27a\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-8a4c506 elementor-widget elementor-widget-text-editor\" data-id=\"8a4c506\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Everything works and Vitest shows the test results<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-b58d24e elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"b58d24e\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-3a8e310\" data-id=\"3a8e310\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-d3b817f elementor-widget elementor-widget-image\" data-id=\"d3b817f\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"309\" src=\"https:\/\/razvanvancea.ro\/blog\/wp-content\/uploads\/2026\/06\/Screenshot-2026-06-25-at-09.11.08-1024x495.png\" class=\"attachment-large size-large wp-image-1571\" alt=\"vitest-results\" srcset=\"https:\/\/razvanvancea.ro\/blog\/wp-content\/uploads\/2026\/06\/Screenshot-2026-06-25-at-09.11.08-1024x495.png 1024w, https:\/\/razvanvancea.ro\/blog\/wp-content\/uploads\/2026\/06\/Screenshot-2026-06-25-at-09.11.08-300x145.png 300w, https:\/\/razvanvancea.ro\/blog\/wp-content\/uploads\/2026\/06\/Screenshot-2026-06-25-at-09.11.08-768x371.png 768w, https:\/\/razvanvancea.ro\/blog\/wp-content\/uploads\/2026\/06\/Screenshot-2026-06-25-at-09.11.08-1536x742.png 1536w, https:\/\/razvanvancea.ro\/blog\/wp-content\/uploads\/2026\/06\/Screenshot-2026-06-25-at-09.11.08-2048x990.png 2048w, https:\/\/razvanvancea.ro\/blog\/wp-content\/uploads\/2026\/06\/Screenshot-2026-06-25-at-09.11.08-850x411.png 850w, https:\/\/razvanvancea.ro\/blog\/wp-content\/uploads\/2026\/06\/Screenshot-2026-06-25-at-09.11.08-24x12.png 24w, https:\/\/razvanvancea.ro\/blog\/wp-content\/uploads\/2026\/06\/Screenshot-2026-06-25-at-09.11.08-36x17.png 36w, https:\/\/razvanvancea.ro\/blog\/wp-content\/uploads\/2026\/06\/Screenshot-2026-06-25-at-09.11.08-48x23.png 48w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/>\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-d64a9c1 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"d64a9c1\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-29f47dd\" data-id=\"29f47dd\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-1aaf24a elementor-widget elementor-widget-spacer\" data-id=\"1aaf24a\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"spacer.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-spacer\">\n\t\t\t<div class=\"elementor-spacer-inner\"><\/div>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-036228c elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"036228c\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-a120644\" data-id=\"a120644\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-c04d407 elementor-widget elementor-widget-text-editor\" data-id=\"c04d407\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Enjoyed this article?<br \/>I share more practical automation tips on\u00a0<a href=\"https:\/\/www.youtube.com\/c\/LearnwithRV\/videos\" target=\"_blank\" rel=\"noopener\"><strong>YouTube<\/strong><\/a>\u00a0and\u00a0<a href=\"https:\/\/www.linkedin.com\/in\/razvanvancea\/\" target=\"_blank\" rel=\"noopener\"><strong>LinkedIn<\/strong><\/a>.<\/p><p><strong>Need structured guidance instead of learning alone?<\/strong><br \/>I offer\u00a0<strong>1-on-1 mentoring<\/strong>\u00a0&#8211; learn more \u2192\u00a0<strong><a href=\"https:\/\/razvanvancea.ro\/1on1.html\" target=\"_blank\" rel=\"noopener\">HERE<\/a><\/strong><\/p><p>Or email me at\u00a0<strong>iamqarv [at] gmail [dot] com<\/strong><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>Unit testing is one of the easiest ways to make your JavaScript code more reliable&#8230;.<\/p>\n","protected":false},"author":2,"featured_media":1575,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[11],"tags":[2],"class_list":["post-1562","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-qa","tag-qa"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.2 - aioseo.com -->\n\t<meta name=\"description\" content=\"Unit testing is one of the easiest ways to make your JavaScript code more reliable. A unit test checks a small piece of code in isolation and confirms that it behaves as expected.In this article, we will set up a very simple testing stack using Vitest then write our first unit tests for a basic\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Razvan Vancea\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/razvanvancea.ro\/blog\/2026\/06\/25\/unit-testing-in-javascript-getting-started-with-vitest-and-jsdom\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.2\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Learn with RV - Tech Blog - #testautomation #qa #programming #linux #devops\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Unit Testing in JavaScript: Getting started with Vitest - Learn with RV - Tech Blog\" \/>\n\t\t<meta property=\"og:description\" content=\"Unit testing is one of the easiest ways to make your JavaScript code more reliable. A unit test checks a small piece of code in isolation and confirms that it behaves as expected.In this article, we will set up a very simple testing stack using Vitest then write our first unit tests for a basic\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/razvanvancea.ro\/blog\/2026\/06\/25\/unit-testing-in-javascript-getting-started-with-vitest-and-jsdom\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2026-06-25T06:06:01+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2026-06-25T06:18:48+00:00\" \/>\n\t\t<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/razvanvancea\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n\t\t<meta name=\"twitter:site\" content=\"@RazvanVancea\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Unit Testing in JavaScript: Getting started with Vitest - Learn with RV - Tech Blog\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Unit testing is one of the easiest ways to make your JavaScript code more reliable. A unit test checks a small piece of code in isolation and confirms that it behaves as expected.In this article, we will set up a very simple testing stack using Vitest then write our first unit tests for a basic\" \/>\n\t\t<meta name=\"twitter:creator\" content=\"@RazvanVancea\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"BlogPosting\",\"@id\":\"https:\\\/\\\/razvanvancea.ro\\\/blog\\\/2026\\\/06\\\/25\\\/unit-testing-in-javascript-getting-started-with-vitest-and-jsdom\\\/#blogposting\",\"name\":\"Unit Testing in JavaScript: Getting started with Vitest - Learn with RV - Tech Blog\",\"headline\":\"Unit Testing in JavaScript: Getting started with Vitest\",\"author\":{\"@id\":\"https:\\\/\\\/razvanvancea.ro\\\/blog\\\/author\\\/iamrv\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/razvanvancea.ro\\\/blog\\\/#person\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/razvanvancea.ro\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/06\\\/Screenshot-2026-06-25-at-09.14.32.png\",\"width\":1376,\"height\":396},\"datePublished\":\"2026-06-25T06:06:01+00:00\",\"dateModified\":\"2026-06-25T06:18:48+00:00\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/razvanvancea.ro\\\/blog\\\/2026\\\/06\\\/25\\\/unit-testing-in-javascript-getting-started-with-vitest-and-jsdom\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/razvanvancea.ro\\\/blog\\\/2026\\\/06\\\/25\\\/unit-testing-in-javascript-getting-started-with-vitest-and-jsdom\\\/#webpage\"},\"articleSection\":\"QA, #qa\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/razvanvancea.ro\\\/blog\\\/2026\\\/06\\\/25\\\/unit-testing-in-javascript-getting-started-with-vitest-and-jsdom\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/razvanvancea.ro\\\/blog\\\/#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/razvanvancea.ro\\\/blog\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/razvanvancea.ro\\\/blog\\\/category\\\/qa\\\/#listItem\",\"name\":\"QA\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/razvanvancea.ro\\\/blog\\\/category\\\/qa\\\/#listItem\",\"position\":2,\"name\":\"QA\",\"item\":\"https:\\\/\\\/razvanvancea.ro\\\/blog\\\/category\\\/qa\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/razvanvancea.ro\\\/blog\\\/2026\\\/06\\\/25\\\/unit-testing-in-javascript-getting-started-with-vitest-and-jsdom\\\/#listItem\",\"name\":\"Unit Testing in JavaScript: Getting started with Vitest\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/razvanvancea.ro\\\/blog\\\/#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/razvanvancea.ro\\\/blog\\\/2026\\\/06\\\/25\\\/unit-testing-in-javascript-getting-started-with-vitest-and-jsdom\\\/#listItem\",\"position\":3,\"name\":\"Unit Testing in JavaScript: Getting started with Vitest\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/razvanvancea.ro\\\/blog\\\/category\\\/qa\\\/#listItem\",\"name\":\"QA\"}}]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/razvanvancea.ro\\\/blog\\\/#person\",\"name\":\"RV\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/razvanvancea.ro\\\/blog\\\/2026\\\/06\\\/25\\\/unit-testing-in-javascript-getting-started-with-vitest-and-jsdom\\\/#personImage\",\"url\":\"https:\\\/\\\/razvanvancea.ro\\\/blog\\\/wp-content\\\/litespeed\\\/avatar\\\/91ce41471f9ba5f15b3ef99e7deed87c.jpg?ver=1790847588\",\"width\":96,\"height\":96,\"caption\":\"RV\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/razvanvancea\\\/\",\"https:\\\/\\\/twitter.com\\\/RazvanVancea\",\"https:\\\/\\\/www.youtube.com\\\/@LearnwithRV\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/razvanvancea\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/razvanvancea.ro\\\/blog\\\/author\\\/iamrv\\\/#author\",\"url\":\"https:\\\/\\\/razvanvancea.ro\\\/blog\\\/author\\\/iamrv\\\/\",\"name\":\"Razvan Vancea\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/razvanvancea.ro\\\/blog\\\/2026\\\/06\\\/25\\\/unit-testing-in-javascript-getting-started-with-vitest-and-jsdom\\\/#authorImage\",\"url\":\"https:\\\/\\\/razvanvancea.ro\\\/blog\\\/wp-content\\\/litespeed\\\/avatar\\\/356548feb901191539c03dd4a0498f58.jpg?ver=1790847589\",\"width\":96,\"height\":96,\"caption\":\"Razvan Vancea\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/razvanvancea.ro\\\/blog\\\/2026\\\/06\\\/25\\\/unit-testing-in-javascript-getting-started-with-vitest-and-jsdom\\\/#webpage\",\"url\":\"https:\\\/\\\/razvanvancea.ro\\\/blog\\\/2026\\\/06\\\/25\\\/unit-testing-in-javascript-getting-started-with-vitest-and-jsdom\\\/\",\"name\":\"Unit Testing in JavaScript: Getting started with Vitest - Learn with RV - Tech Blog\",\"description\":\"Unit testing is one of the easiest ways to make your JavaScript code more reliable. A unit test checks a small piece of code in isolation and confirms that it behaves as expected.In this article, we will set up a very simple testing stack using Vitest then write our first unit tests for a basic\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/razvanvancea.ro\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/razvanvancea.ro\\\/blog\\\/2026\\\/06\\\/25\\\/unit-testing-in-javascript-getting-started-with-vitest-and-jsdom\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/razvanvancea.ro\\\/blog\\\/author\\\/iamrv\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/razvanvancea.ro\\\/blog\\\/author\\\/iamrv\\\/#author\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/razvanvancea.ro\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/06\\\/Screenshot-2026-06-25-at-09.14.32.png\",\"@id\":\"https:\\\/\\\/razvanvancea.ro\\\/blog\\\/2026\\\/06\\\/25\\\/unit-testing-in-javascript-getting-started-with-vitest-and-jsdom\\\/#mainImage\",\"width\":1376,\"height\":396},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/razvanvancea.ro\\\/blog\\\/2026\\\/06\\\/25\\\/unit-testing-in-javascript-getting-started-with-vitest-and-jsdom\\\/#mainImage\"},\"datePublished\":\"2026-06-25T06:06:01+00:00\",\"dateModified\":\"2026-06-25T06:18:48+00:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/razvanvancea.ro\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/razvanvancea.ro\\\/blog\\\/\",\"name\":\"Learn with RV - Tech Blog\",\"description\":\"#testautomation #qa #programming #linux #devops\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/razvanvancea.ro\\\/blog\\\/#person\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Unit Testing in JavaScript: Getting started with Vitest - Learn with RV - Tech Blog","description":"Unit testing is one of the easiest ways to make your JavaScript code more reliable. A unit test checks a small piece of code in isolation and confirms that it behaves as expected.In this article, we will set up a very simple testing stack using Vitest then write our first unit tests for a basic","canonical_url":"https:\/\/razvanvancea.ro\/blog\/2026\/06\/25\/unit-testing-in-javascript-getting-started-with-vitest-and-jsdom\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"BlogPosting","@id":"https:\/\/razvanvancea.ro\/blog\/2026\/06\/25\/unit-testing-in-javascript-getting-started-with-vitest-and-jsdom\/#blogposting","name":"Unit Testing in JavaScript: Getting started with Vitest - Learn with RV - Tech Blog","headline":"Unit Testing in JavaScript: Getting started with Vitest","author":{"@id":"https:\/\/razvanvancea.ro\/blog\/author\/iamrv\/#author"},"publisher":{"@id":"https:\/\/razvanvancea.ro\/blog\/#person"},"image":{"@type":"ImageObject","url":"https:\/\/razvanvancea.ro\/blog\/wp-content\/uploads\/2026\/06\/Screenshot-2026-06-25-at-09.14.32.png","width":1376,"height":396},"datePublished":"2026-06-25T06:06:01+00:00","dateModified":"2026-06-25T06:18:48+00:00","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/razvanvancea.ro\/blog\/2026\/06\/25\/unit-testing-in-javascript-getting-started-with-vitest-and-jsdom\/#webpage"},"isPartOf":{"@id":"https:\/\/razvanvancea.ro\/blog\/2026\/06\/25\/unit-testing-in-javascript-getting-started-with-vitest-and-jsdom\/#webpage"},"articleSection":"QA, #qa"},{"@type":"BreadcrumbList","@id":"https:\/\/razvanvancea.ro\/blog\/2026\/06\/25\/unit-testing-in-javascript-getting-started-with-vitest-and-jsdom\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/razvanvancea.ro\/blog\/#listItem","position":1,"name":"Home","item":"https:\/\/razvanvancea.ro\/blog\/","nextItem":{"@type":"ListItem","@id":"https:\/\/razvanvancea.ro\/blog\/category\/qa\/#listItem","name":"QA"}},{"@type":"ListItem","@id":"https:\/\/razvanvancea.ro\/blog\/category\/qa\/#listItem","position":2,"name":"QA","item":"https:\/\/razvanvancea.ro\/blog\/category\/qa\/","nextItem":{"@type":"ListItem","@id":"https:\/\/razvanvancea.ro\/blog\/2026\/06\/25\/unit-testing-in-javascript-getting-started-with-vitest-and-jsdom\/#listItem","name":"Unit Testing in JavaScript: Getting started with Vitest"},"previousItem":{"@type":"ListItem","@id":"https:\/\/razvanvancea.ro\/blog\/#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/razvanvancea.ro\/blog\/2026\/06\/25\/unit-testing-in-javascript-getting-started-with-vitest-and-jsdom\/#listItem","position":3,"name":"Unit Testing in JavaScript: Getting started with Vitest","previousItem":{"@type":"ListItem","@id":"https:\/\/razvanvancea.ro\/blog\/category\/qa\/#listItem","name":"QA"}}]},{"@type":"Person","@id":"https:\/\/razvanvancea.ro\/blog\/#person","name":"RV","image":{"@type":"ImageObject","@id":"https:\/\/razvanvancea.ro\/blog\/2026\/06\/25\/unit-testing-in-javascript-getting-started-with-vitest-and-jsdom\/#personImage","url":"https:\/\/razvanvancea.ro\/blog\/wp-content\/litespeed\/avatar\/91ce41471f9ba5f15b3ef99e7deed87c.jpg?ver=1790847588","width":96,"height":96,"caption":"RV"},"sameAs":["https:\/\/www.facebook.com\/razvanvancea\/","https:\/\/twitter.com\/RazvanVancea","https:\/\/www.youtube.com\/@LearnwithRV","https:\/\/www.linkedin.com\/in\/razvanvancea"]},{"@type":"Person","@id":"https:\/\/razvanvancea.ro\/blog\/author\/iamrv\/#author","url":"https:\/\/razvanvancea.ro\/blog\/author\/iamrv\/","name":"Razvan Vancea","image":{"@type":"ImageObject","@id":"https:\/\/razvanvancea.ro\/blog\/2026\/06\/25\/unit-testing-in-javascript-getting-started-with-vitest-and-jsdom\/#authorImage","url":"https:\/\/razvanvancea.ro\/blog\/wp-content\/litespeed\/avatar\/356548feb901191539c03dd4a0498f58.jpg?ver=1790847589","width":96,"height":96,"caption":"Razvan Vancea"}},{"@type":"WebPage","@id":"https:\/\/razvanvancea.ro\/blog\/2026\/06\/25\/unit-testing-in-javascript-getting-started-with-vitest-and-jsdom\/#webpage","url":"https:\/\/razvanvancea.ro\/blog\/2026\/06\/25\/unit-testing-in-javascript-getting-started-with-vitest-and-jsdom\/","name":"Unit Testing in JavaScript: Getting started with Vitest - Learn with RV - Tech Blog","description":"Unit testing is one of the easiest ways to make your JavaScript code more reliable. A unit test checks a small piece of code in isolation and confirms that it behaves as expected.In this article, we will set up a very simple testing stack using Vitest then write our first unit tests for a basic","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/razvanvancea.ro\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/razvanvancea.ro\/blog\/2026\/06\/25\/unit-testing-in-javascript-getting-started-with-vitest-and-jsdom\/#breadcrumblist"},"author":{"@id":"https:\/\/razvanvancea.ro\/blog\/author\/iamrv\/#author"},"creator":{"@id":"https:\/\/razvanvancea.ro\/blog\/author\/iamrv\/#author"},"image":{"@type":"ImageObject","url":"https:\/\/razvanvancea.ro\/blog\/wp-content\/uploads\/2026\/06\/Screenshot-2026-06-25-at-09.14.32.png","@id":"https:\/\/razvanvancea.ro\/blog\/2026\/06\/25\/unit-testing-in-javascript-getting-started-with-vitest-and-jsdom\/#mainImage","width":1376,"height":396},"primaryImageOfPage":{"@id":"https:\/\/razvanvancea.ro\/blog\/2026\/06\/25\/unit-testing-in-javascript-getting-started-with-vitest-and-jsdom\/#mainImage"},"datePublished":"2026-06-25T06:06:01+00:00","dateModified":"2026-06-25T06:18:48+00:00"},{"@type":"WebSite","@id":"https:\/\/razvanvancea.ro\/blog\/#website","url":"https:\/\/razvanvancea.ro\/blog\/","name":"Learn with RV - Tech Blog","description":"#testautomation #qa #programming #linux #devops","inLanguage":"en-US","publisher":{"@id":"https:\/\/razvanvancea.ro\/blog\/#person"}}]},"og:locale":"en_US","og:site_name":"Learn with RV - Tech Blog - #testautomation #qa #programming #linux #devops","og:type":"article","og:title":"Unit Testing in JavaScript: Getting started with Vitest - Learn with RV - Tech Blog","og:description":"Unit testing is one of the easiest ways to make your JavaScript code more reliable. A unit test checks a small piece of code in isolation and confirms that it behaves as expected.In this article, we will set up a very simple testing stack using Vitest then write our first unit tests for a basic","og:url":"https:\/\/razvanvancea.ro\/blog\/2026\/06\/25\/unit-testing-in-javascript-getting-started-with-vitest-and-jsdom\/","article:published_time":"2026-06-25T06:06:01+00:00","article:modified_time":"2026-06-25T06:18:48+00:00","article:publisher":"https:\/\/www.facebook.com\/razvanvancea","twitter:card":"summary_large_image","twitter:site":"@RazvanVancea","twitter:title":"Unit Testing in JavaScript: Getting started with Vitest - Learn with RV - Tech Blog","twitter:description":"Unit testing is one of the easiest ways to make your JavaScript code more reliable. A unit test checks a small piece of code in isolation and confirms that it behaves as expected.In this article, we will set up a very simple testing stack using Vitest then write our first unit tests for a basic","twitter:creator":"@RazvanVancea"},"aioseo_meta_data":{"post_id":"1562","title":null,"description":null,"keywords":null,"keyphrases":{"focus":[],"additional":[]},"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"BlogPosting","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":null,"frequency":"default","local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":{"faqs":[],"keyPoints":[],"schemas":[],"titles":[],"descriptions":[],"socialPosts":{"email":[],"linkedin":[],"twitter":[],"facebook":[],"instagram":[]}},"created":"2026-06-25 05:57:38","updated":"2026-09-04 08:26:32","seo_analyzer_scan_date":null,"focus_keyword":null,"additional_keywords":null,"truseo_locale":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/razvanvancea.ro\/blog\/\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">\u00bb<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/razvanvancea.ro\/blog\/category\/qa\/\" title=\"QA\">QA<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">\u00bb<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tUnit Testing in JavaScript: Getting started with Vitest\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/razvanvancea.ro\/blog\/"},{"label":"QA","link":"https:\/\/razvanvancea.ro\/blog\/category\/qa\/"},{"label":"Unit Testing in JavaScript: Getting started with Vitest","link":"https:\/\/razvanvancea.ro\/blog\/2026\/06\/25\/unit-testing-in-javascript-getting-started-with-vitest-and-jsdom\/"}],"jetpack-related-posts":[],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/razvanvancea.ro\/blog\/wp-content\/uploads\/2026\/06\/Screenshot-2026-06-25-at-09.14.32.png","_links":{"self":[{"href":"https:\/\/razvanvancea.ro\/blog\/wp-json\/wp\/v2\/posts\/1562","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/razvanvancea.ro\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/razvanvancea.ro\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/razvanvancea.ro\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/razvanvancea.ro\/blog\/wp-json\/wp\/v2\/comments?post=1562"}],"version-history":[{"count":13,"href":"https:\/\/razvanvancea.ro\/blog\/wp-json\/wp\/v2\/posts\/1562\/revisions"}],"predecessor-version":[{"id":1581,"href":"https:\/\/razvanvancea.ro\/blog\/wp-json\/wp\/v2\/posts\/1562\/revisions\/1581"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/razvanvancea.ro\/blog\/wp-json\/wp\/v2\/media\/1575"}],"wp:attachment":[{"href":"https:\/\/razvanvancea.ro\/blog\/wp-json\/wp\/v2\/media?parent=1562"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/razvanvancea.ro\/blog\/wp-json\/wp\/v2\/categories?post=1562"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/razvanvancea.ro\/blog\/wp-json\/wp\/v2\/tags?post=1562"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}