{"record":{"id":"59faaf10e9631c88","repo":"angular/angular-cli","slug":"no-test-target-found-for-project-options-proj-59faaf","errorCode":null,"errorMessage":"No \"test\" target found for project \"${options.project}\". A \"test\" target is required to generate a karma configuration.","messagePattern":"No \"test\" target found for project \"(.+?)\"\\. A \"test\" target is required to generate a karma configuration\\.","errorType":"exception","errorClass":"SchematicsException","httpStatus":null,"severity":"error","filePath":"packages/schematics/angular/config/index.ts","lineNumber":124,"sourceCode":"      filter((p) => p.endsWith('.browserslistrc.template')),\n      // The below is replaced by bazel `npm_package`.\n      applyTemplates({ baselineDate: 'BASELINE-DATE-PLACEHOLDER' }),\n      move(projectRoot),\n    ]),\n  );\n}\n\nfunction addKarmaConfig(options: ConfigOptions): Rule {\n  return (_, context) =>\n    updateWorkspace((workspace) => {\n      const project = workspace.projects.get(options.project);\n      if (!project) {\n        throw new SchematicsException(`Project name \"${options.project}\" doesn't not exist.`);\n      }\n\n      const testTarget = project.targets.get('test');\n      if (!testTarget) {\n        throw new SchematicsException(\n          `No \"test\" target found for project \"${options.project}\".` +\n            ' A \"test\" target is required to generate a karma configuration.',\n        );\n      }\n\n      if (\n        testTarget.builder !== AngularBuilder.Karma &&\n        testTarget.builder !== AngularBuilder.BuildKarma &&\n        testTarget.builder !== AngularBuilder.BuildUnitTest\n      ) {\n        throw new SchematicsException(\n          `Cannot add a karma configuration as builder for \"test\" target in project does not` +\n            ` use \"${AngularBuilder.Karma}\", \"${AngularBuilder.BuildKarma}\", or ${AngularBuilder.BuildUnitTest}.`,\n        );\n      }\n\n      testTarget.options ??= {};\n      if (testTarget.builder !== AngularBuilder.BuildUnitTest) {","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/schematics/angular/config/index.ts#L106-L142","documentation":"`addKarmaConfig` requires the target project to already define a `test` architect target. The karma configuration file (`karma.conf.js`) is generated to be wired into an existing test target, so when `project.targets.get('test')` returns nothing the schematic throws this exception instead of creating a dangling config.","triggerScenarios":"Running `ng generate config <project> --type karma` on a project whose angular.json entry has no `test` target — e.g. a newly created application or library without unit testing set up, or after the test target was manually deleted.","commonSituations":"Legacy workspaces where testing was never initialized; projects where `ng generate config` is run before any test builder was added; picking the wrong project name so a project without tests is targeted.","solutions":["Add a `test` target to the project in angular.json (with `@angular/build:unit-test`, `@angular-devkit/build-angular:karma`, or `@angular-devkit/build-angular:build-karma`) before generating the karma config.","Re-run `ng generate config <project> --type karma` after the test target exists.","Confirm you are targeting the intended project; another project may already have a test target."],"exampleFix":"// angular.json before: project has no \"test\" architect entry\n// after\n\"architect\": { \"test\": { \"builder\": \"@angular-devkit/build-angular:karma\", \"options\": { \"main\": \"src/test.ts\" } } }","handlingStrategy":"validation","validationCode":"const project = angularJson.projects[options.project];\nconst testTarget = project?.architect?.test ?? project?.targets?.test;\nif (!testTarget) {\n  throw new Error(`Project \"${options.project}\" has no \"test\" target; cannot generate karma.conf.js.`);\n}","typeGuard":"function hasTestTarget(p: any): boolean {\n  return !!(p?.architect?.test ?? p?.targets?.test);\n}","tryCatchPattern":"try {\n  await runSchematic('config', { project, type: 'karma' });\n} catch (e) {\n  if (e instanceof SchematicsException && e.message.includes('No \"test\" target')) {\n    console.error('Initialize the test target before generating a karma config.');\n  } else throw e;\n}","preventionTips":["Add a test target (karma or unit-test builder) before running `--type karma`.","Audit angular.json for projects missing the test architect entry in multi-project workspaces.","Confirm the intended project name before running the schematic."],"tags":["angular","schematics","missing-target","karma"],"backgroundTag":"missing-test-target","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}