Testing learning materials

Free courses

Polish free courses

Additional content

Jest

Vitest: an alternative to Jest

Why choose Vitest?

  • built in typescript support
  • chai and jest compatible assertions
  • works out of the box with super fast build tool: Vite

Vitest materials

Import modules for testing as globals in config

import { defineConfig } from 'vite';
import { svelte } from '@sveltejs/vite-plugin-svelte';

export default defineConfig({
	plugins: [svelte({ hot: !process.env.VITEST })],
	test: {
		globals: true,
		environment: 'jsdom',
	},
});

End to end testing

Testing principles

Structure of a test

  • Arrange - set up the test data, test conditions, and test environment
  • Act - run logic that should be tested (eg. execute function), click a button
  • Assert - compare the expected result with the actual result

Types of tests

  • Unit tests - testing an isolated function
  • Integration tests - testing a component that uses other components, testing things working together
  • End to end tests - testing user interaction with UI

Other testing materials