alternatives to change TestBed configurations without creating the test.ts files

Open
#24,345 6 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
angular, typescript
Domain
testing, tooling

Research direction

Start by tracing how angular.json test options are handled and how the test.ts bootstrap is generated or replaced. Use the requested TestBed settings and custom test pattern as the acceptance cases; done means projects can configure them without creating test.ts files.

Written by the indexing model from the issue text.

Description

area: @angular-devkit/build-angular devkit/build-angular:karma feature feature: insufficient votes
Which @angular/* package(s) are relevant/related to the feature request?

core

Description

with Angular 15, now the test.ts file doesn't get generated by default, so it's not an easy task to change the TestBed configurations for example to enable errorOnUnknownElements
it will also be nice if we can change the pattern of the tests

Proposed solution

to add the configurations inside the angular.json files in the options section of test

something like

"options": {
  "polyfills": [
    "zone.js",
    "zone.js/testing"
  ],
  "tsConfig": "tsconfig.spec.json",
  "inlineStyleLanguage": "scss",
  "assets": [
    "src/favicon.ico",
    "src/assets"
  ],
  "styles": [
    "src/styles.scss"
  ],
  "scripts": [],
  "errorOnUnknownElements": true,      <--- 
  "errorOnUnknownProperties": true,    <--- 
  "pattern": "\.custom-spec\.ts$"      <--- 
}
Alternatives considered

to be able to enable them globally from any script (to create a js file and add it to the scripts of the test) with something like

getTestBed().setoptions({
  errorOnUnknownElements: true,
  errorOnUnknownProperties: true,
  pattern: /\.custom-spec\.ts$/
});
Dominant language
TypeScript
Stars
27k
Forks
11.8k
Avg merge
16h 35m
Merged PRs (30d)
176

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from angular/angular-cli

All issues in angular/angular-cli

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.