Angular 18 Library & Showcase - ng test doesn't find Spec files

Discussão em 'Angular' iniciado por Eric R, Outubro 29, 2024.

  1. Eric R

    Eric R Guest

    tldr; Trying to determine why running ng test library is returning Executed 0 of 0 SUCCESS.

    I have an Angular Workspace setup with two projects:

    • Workspace
      • Projects
        • Library
        • Showcase

    The Library project and Showcase projects are separate Angular applications with a singular angular.json file.

    The Library Project, is made up of reusable components to be distributed across different Angular applications, and is structured as (using ButtonComponent as an example):

    • button
      • src
        • button.component.html
        • button.component.spec.ts
        • button.component.ts
      • index.ts
      • ng-package.json
      • public-api.ts

    To run Unit Tests on the Library project, I call ng test library (where library is the Project name of the Library application); however, no tests are found.

    I'm not positive, but I think the issue is with my tsconfig.spec.json file:

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


    Even though it's specified to include all *.spec.ts files, it doesn't seem to be finding them. This file is at the path /projects/library/tsconfig.spec.json.

    My tsconfig.json file is at the root.

    Within my angular.json file, this is how test is configured for the library project:

    "test": {
    "builder": "@angular-devkit/build-angular:karma",
    "options": {
    "polyfills": ["zone.js", "zone.js/testing"],
    "tsConfig": "projects/library/tsconfig.spec.json",
    "karmaConfig": "karma.conf.js",
    "inlineStyleLanguage": "scss",
    "codeCoverage": true
    }
    }


    I've tried everything I know and everything looks like it's pointing to the proper things. I even tried including button/src/*.spec.ts in tsconfig.spec.json and it still didn't find the at test.

    Can someone help me figure out what I'm missing here?

    TIA!

    Continue reading...

Compartilhe esta Página