Search code examples
angularjestjsnomachine-nx

Run only one Jest test file with NX


nx run myproject:test --testFile=libs/myproject/src/lib/guards/role.guard.spec.ts

I expect only a single .spec file to be tested. However, the error output shows additional .spec files.

$ nx run myproject:test --testFile=libs/myproject/src/lib/guards/role.guard.spec.ts 

FAIL   core  libs/myproject/src/lib/guards/role.guard.spec.ts
● Test suite failed to run

    libs/myproject/src/lib/auth/auth.service.ts:49:11 - error TS2564: Property 'sessions' has...

    49   private sessions: string;
    libs/myproject/src/lib/auth/auth.service.ts:51:11 - error TS2564...

... Many more lines ...

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        6.953 s
Ran all test suites matching /libs\\myproject\\src\\lib\\guards\\role.guard.spec.ts/i.

Why are extra tests being run such as libs/myproject/src/lib/auth/secure.directive.spec.ts ?


Solution

  • I must have mis-read the output when I posted this. It looks like the nx jest commands I posted, were actually working.