GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||
GeezerVison is showing angular.dev — Testing • Overview • Angular Testing your Angular application helps you check that it is working as you expect. Unit tests are crucial for catching bugs early, ensuring code quality, and facilitating safe refactoring. NOTE: This guide covers the default testing setup for new Angular CLI projects, which uses Vitest. If you are migrating an existing project from Karma, see the Migrating from Karma to Vitest guide. Karma is still supported; for more information, see the Karma testing guide. Set up for testingThe Angular CLI downloads and installs everything you need to test an Angular application with the Vitest testing framework. New projects include Vitest runs your unit tests in a Node.js environment. To simulate the browser's DOM, Vitest uses a library called The project you create with the CLI is immediately ready to test. Run the
The The console output looks like this:
The ConfigurationThe Angular CLI handles most of the Vitest configuration for you. You can customize the test behavior by modifying the Angular.json options
Global test setup and providersThe For example, you could create a src/test-providers.ts
You would then reference this file in your
HELPFUL: When creating new TypeScript files for test setup or providers, like Advanced Vitest configurationFor advanced use cases, you can provide a custom Vitest configuration file using the IMPORTANT: While using a custom configuration enables advanced options, the Angular team does not provide support for the contents of the configuration file or for any third-party plugins. The CLI will also override certain properties ( You can create a Vitest configuration file (e.g.,
You can also generate a base configuration file using the CLI:
This creates a HELPFUL: Read more about Vitest configuration in the official Vitest documentation. Code coverageYou can generate a code coverage report by adding the For more detailed information, see the Code coverage guide. Running tests in a browserWhile the default Node.js environment is faster for most unit tests, you can also run your tests in a real browser. This is useful for tests that rely on browser-specific APIs (like rendering) or for debugging. To run tests in a browser, you must first install a browser provider. Read more about Vitest's browser mode in the official documentation. Once the provider is installed, you can run your tests in the browser by configuring the
Choose one of the following browser providers based on your needs: PlaywrightPlaywright is a browser automation library that supports Chromium, Firefox, and WebKit. npm
yarn
pnpm
bun
WebdriverIOWebdriverIO is a browser and mobile automation test framework that supports Chrome, Firefox, Safari, and Edge. npm
yarn
pnpm
bun
PreviewThe npm
yarn
pnpm
bun
HELPFUL: For more advanced browser-specific configuration, see the Advanced Vitest configuration section. Other test frameworksYou can also unit test an Angular application with other testing libraries and test runners. Each library and runner has its own installation procedures, configuration, and syntax. Testing in continuous integrationA robust test suite is a key part of a continuous integration (CI) pipeline. CI servers let you automate your tests to run on every commit and pull request. To test your Angular application in a CI server, run the standard test command:
Most CI servers set a If your CI server does not set this variable, or if you need to force single-run mode manually, you can use the
More information on testingAfter you've set up your application for testing, you might find the following testing guides useful.
| ||||||||||||||||||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |