briebug / jest-schematic

Angular schematic for adding Jest and the required files to an Angular CLI project
MIT License
319 stars 39 forks source link

configure to allow raw testing of individual files #140

Open robbiemu opened 1 year ago

robbiemu commented 1 year ago

Is your feature request related to a problem? Please describe.

I would like to be able to directly test individual files. When setting jest up on my own, I used to be able to: jest ./src/app/app.component.spec.ts

and this comes in handy especially in vscode where I might drag and drop the file directly to the terminal..

now that produces:

Determining test suites to run...
ngcc-jest-processor: running ngcc
 FAIL  src/app/app.component.spec.ts
  AppComponent
    ✕ should create the app (3 ms)
    ✕ should have as title 'ang15-test' (6 ms)
    ✕ should render title (1 ms)

  ● AppComponent › should create the app

    Need to call TestBed.initTestEnvironment() first
...

likewise, I cannot call ng test directly with the filename:

ng test ./src/app/app.component.spec.ts

Error: Invalid values:
  Argument: project, Given: "./src/app/app.component.spec.ts", Choices: "ang15-test"

ng test -- ./src/app/app.component.spec.ts
Option '--' has been specified multiple times. The value './src/app/app.component.spec.ts' will be used.
Error: Schema validation failed with the following errors:
  Data path "/" must be array.

Describe the solution you'd like A clear and concise description of what you want to happen.

I should be able to test specific files directly on the commandline, such as:

jest <filename>

Describe alternatives you've considered As I've had that working in multiple repos before, I am sure I will be able to figure it out with modern angular 15 now. I just havent located the issue yet.