ts-jest --watch doesn't detect changes to imported class properties

Viewed 78

My setup right now is pretty simple. I am creating a class and running ts-jest to check for the properties. The issue is when I run "jest --watch" or "jest --watchAll" and I remove a property of the class, my tests continue to run fine. They should error out stating that "1 Argument is expected instead of 2" but it does not. If I kill jest and just re-run it normally, tests work fine. Additionally, if I just SAVE inside the test.ts file, then jest detects the issue and throws an error.

I also tried "--no-cache" when running watch but that didn't work. I am relatively new to Typescript and JEST so any guidance is greatly appreciated. Here are steps to replicate:

  1. run "jest --watchAll --no-cache" (optional to run no-cache I saw no difference)
  2. Remove the 2 lines that have 'value' (lines annotated below) then SAVE.
  3. You should now see that the test still passes.
  4. Kill Jest then re-run it. Test now fails due receiving invalid number of arguments.

I setup a basic typescript project and installed jest. Here are relevant files:

card_types.ts:

export class Card {
    
    // can add things like image and such here.
    readonly category: string;
    readonly value: number;    //<----- Remove me

    constructor(c: string, v: number) {   //<----- Remove ", v: number"
        this.category = c;
        this.value = v;    //<----- Remove me
    }

}

card_types.test.ts:

import { Card } from './card_types';

describe('Card Class', () => {
  it('should create an instance of Card with category = Action', () => {
    const my_card = new Card('Action');
    console.log(my_card);

    expect(my_card.category).toBe('Action');
  });
});

tsconfig.json:

{
  "compilerOptions": {
    
    "target": "es2016",                                  
    "module": "commonjs",
    "esModuleInterop": true,                             
    "forceConsistentCasingInFileNames": true,            
    "strict": true,                                      
    "skipLibCheck": true                                 
  }
}

jest.config.js:

/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
  globals: {
    'ts-jest': {
      tsconfig: 'tsconfig.json',
    },
  },
  preset: 'ts-jest',
  testEnvironment: 'node',
  testMatch: ['**/*.test.(ts|js)'],
};
0 Answers
Related