<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Unit test Archives - Conseil HU</title>
	<atom:link href="https://hyyyanick.com/category/unit-test/feed/" rel="self" type="application/rss+xml" />
	<link>https://hyyyanick.com/category/unit-test/</link>
	<description>Sharing, Growing</description>
	<lastBuildDate>Thu, 21 May 2026 13:16:26 +0000</lastBuildDate>
	<language>fr-FR</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://hyyyanick.com/wp-content/uploads/2026/04/cropped-Site-logo-32x32.png</url>
	<title>Unit test Archives - Conseil HU</title>
	<link>https://hyyyanick.com/category/unit-test/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Modernizing Angular Testing: From Karma/Jasmine to Vitest</title>
		<link>https://hyyyanick.com/modernizing-angular-testing-from-karma-jasmine-to-vitest/</link>
					<comments>https://hyyyanick.com/modernizing-angular-testing-from-karma-jasmine-to-vitest/#respond</comments>
		
		<dc:creator><![CDATA[Yiyan HU]]></dc:creator>
		<pubDate>Thu, 21 May 2026 12:19:32 +0000</pubDate>
				<category><![CDATA[Angular]]></category>
		<category><![CDATA[Frontend]]></category>
		<category><![CDATA[Unit test]]></category>
		<guid isPermaLink="false">https://hyyyanick.com/?p=75</guid>

					<description><![CDATA[<p>If you’ve worked on Angular projects long enough, you probably know Karma. It worked for years. But in modern frontend development, slow test startup, browser dependency, and awkward debugging start to feel outdated. The test framework Vitest becomes official and...</p>
<p>The post <a href="https://hyyyanick.com/modernizing-angular-testing-from-karma-jasmine-to-vitest/">Modernizing Angular Testing: From Karma/Jasmine to Vitest</a> appeared first on <a href="https://hyyyanick.com">Conseil HU</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>If you’ve worked on Angular projects long enough, you probably know Karma.</p>



<p>It worked for years. But in modern frontend development, slow test startup, browser dependency, and awkward debugging start to feel outdated.</p>



<p>The test framework Vitest becomes official and default for new Angular projects.</p>



<p>Here is what worked and what we learned from migration.</p>



<h1 class="wp-block-heading">Why move away from Karma?</h1>



<p>To have a briefly comparaison between the two frameworks:</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>Karma</th><th>Vitest</th></tr></thead><tbody><tr><td>Browser-based</td><td>Node-based</td></tr><tr><td>Slower startup</td><td>Fast startup</td></tr><tr><td>Harder debugging</td><td>Better DX with </td></tr><tr><td>Legacy Angular default</td><td>Modern ecosystem</td></tr><tr><td>Weak watch mode</td><td>Excellent watch mode</td></tr></tbody></table></figure>



<h2 class="wp-block-heading">Installation</h2>



<p>If you are using Angular, in the official documentation, we have this article helping to migrate https://angular.dev/guide/testing/migrating-to-vitest</p>



<p>I will not dive into this too much.</p>



<h2 class="wp-block-heading">Configuration</h2>



<p>After installing <strong>vitest, jsdom/ happy-dom</strong>, this is where your real experience helps. To create your <strong>vitest.config.ts</strong></p>



<p>A basic config could be like this:</p>



<pre class="wp-block-code"><code>/// &lt;reference types="vitest" />
import { defineConfig } from 'vite';
import tsconfigPaths from 'vite-tsconfig-paths';

export default defineConfig({
  plugins: &#91;tsconfigPaths()],
  test: {
    globals: true,
    environment: 'jsdom',
    setupFiles: &#91;'src/test-setup.ts']
  }
});</code></pre>



<p>Some specifique configs example:</p>



<pre class="wp-block-code"><code>test: {
        // use the following configs will improve the speed of tests
        isolate: false,
        pool: 'threads',
        css: false,
        // Test reporters (for test execution results)
        reporters: &#91;
            'default',
            &#91;'junit', { outputFile: path to the file }],
            &#91;'junit', { outputFile: path to the file }],
        ],
        // Coverage configuration (for code coverage)
        coverage: {
            provider: 'v8',
            reporter: &#91;], // file type can be 'lcov', 'text', 'cobertura'
            reportsDirectory: reportsDir,
            exclude: &#91;
                './src/test-setup.ts'
            ]
        }
    }</code></pre>



<p>Another change is in <strong>angular.json</strong> file. In addition to the documentation, we can have some other updates:</p>



<pre class="wp-block-code"><code>"test": {
          "builder": "@angular/build:unit-test",
          "options": {
            "runner": "vitest",
            "runnerConfig": "vitest.config.ts", // to tell using this config
            "coverageReporters": &#91;"html", "lcov"],
            "coverage": true,</code></pre>



<h2 class="wp-block-heading">Refactor code from Karma to Vitest</h2>



<p>In the doc, angular CLI provides <strong>ng g @schematics/angular:refactor-jasmine-vitest</strong> to globally refactor some part of code. But we still, in some cases like <a href="https://angular.dev/api/core/testing/fakeAsync"><code>fakeAsync</code></a>, <a href="https://angular.dev/api/core/testing/flush"><code>flush</code></a> or <a href="https://angular.dev/api/core/testing/waitForAsync"><code>waitForAsync</code></a>, refactor the code manually even though it covers a lot.</p>



<p>I would share some exemples later in another post.</p>



<p></p>
<p>The post <a href="https://hyyyanick.com/modernizing-angular-testing-from-karma-jasmine-to-vitest/">Modernizing Angular Testing: From Karma/Jasmine to Vitest</a> appeared first on <a href="https://hyyyanick.com">Conseil HU</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://hyyyanick.com/modernizing-angular-testing-from-karma-jasmine-to-vitest/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
