angularjestjsts-jestjest-preset-angular

How to make jest only run testing for the files in src folder Angular?


I am learning how to setup jest testing in angular. I follow the instruction of jest-preset-angular.

I can successfully make the jest run in angular, but my app also has two submodules in the root, which jest gives a lot of errors on that. I would like to avoid that for now.

I wonder how to set up configuration for jest or jest-preset-angular to only run testing in src folder?


I have two files regarding the jest setup in the <rootDir>:

# jest.config.js
module.exports = {
  preset: 'jest-preset-angular',
  setupFilesAfterEnv: ['<rootDir>/setup-jest.ts'],
};
# setup-jest.ts
import 'jest-preset-angular/setup-jest';

Solution

  • You can set the roots property in the jest.config.js to any directory you want. The example below only runs tests that are under /src/test/

    module.exports = {
      preset: 'jest-preset-angular',
      roots: ['<rootDir>/src/test/']
    };