Socket
Socket
Sign inDemoInstall

jest-preset-angular

Package Overview
Dependencies
6
Maintainers
3
Versions
131
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    jest-preset-angular

Jest preset configuration for Angular projects


Version published
Weekly downloads
574K
decreased by-23.14%
Maintainers
3
Created
Weekly downloads
 

Changelog

Source

14.0.3 (2024-02-16)

Features

  • support signal queries in Angular 17.2 (a57ad7d)

Readme

Source

Jest Preset Angular

A preset of Jest configuration for Angular projects.

Build Status NPM Version GitHub license

Our online documentation is available at https://thymikee.github.io/jest-preset-angular/

This is a part of the article: Testing Angular faster with Jest.

Getting Started

These instructions will get you setup to use jest-preset-angular in your project. For more detailed documentation, please check online documentation.

Install using yarn:

yarn add -D jest jest-preset-angular @types/jest

Or npm:

npm install -D jest jest-preset-angular @types/jest

Configuration

In your project root, create setup-jest.ts file with following contents:

import 'jest-preset-angular/setup-jest';

Add the following section:

  • to your root jest.config.js
// jest.config.js
module.exports = {
  preset: 'jest-preset-angular',
  setupFilesAfterEnv: ['<rootDir>/setup-jest.ts'],
  globalSetup: 'jest-preset-angular/global-setup',
};
  • or to your root package.json
{
  "jest": {
    "preset": "jest-preset-angular",
    "setupFilesAfterEnv": ["<rootDir>/setup-jest.ts"],
    "globalSetup": "jest-preset-angular/global-setup"
  }
}

Adjust your tsconfig.spec.json to be:

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "outDir": "./out-tsc/spec",
    "module": "CommonJs",
    "types": ["jest"]
  },
  "include": ["src/**/*.spec.ts", "src/**/*.d.ts"]
}

IMPORTANT

Angular doesn't support native async/await in testing with target higher than ES2016, see https://github.com/angular/components/issues/21632#issuecomment-764975917

Migration from Angular < 13

Check out our Migration from Angular < 13 guidance

Angular Ivy

Check out our Angular Ivy guidance

Example projects with base Jest configuration

We have example apps to provide a basic setup to use Jest in an Angular project. The examples folder consist of several example Angular applications from v13 onwards as well as example projects with yarn workspace or monorepo structure.

Built With

  • TypeScript - JavaScript that scales
  • Angular - The modern web developer's platform
  • ts-jest - Jest transformer for TypeScript

Authors/maintainers

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Keywords

FAQs

Last updated on 16 Feb 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc