I have tried to get Jest to run properly in Visual Studio code. While I can debug Typescript without an issue, I am unable to get to the proper lines on included functions with Jest.

I have a test file that imports my module:

import { Validate } from "./validate";

describe('Test the Validate', () => {
    it('should return true', () => {
        expect(Validate('abc')).toBeTruthy();
    });

    it('should return false', () => {
        expect(Validate('cba')).toBeFalsy();
    });
});

validate.ts:

export function Validate(Text:string):boolean {
    if (Text === 'abc') {
        return true;
    }
    return false;
}

I place a break point on the expect(Validate('abc')).toBeTruthy(); line, which does seem to cause the code to stop. When I press F11 to step into the function, I do go to the source file, but my cursor is at the end of the file. I can seem to move along with F10 to do the debugging, but I do not see a proper source line.

I have added sourceMaps: true, to my launch.json.

launch.json

{
    "type": "node",
    "request": "launch",
    "name": "Jest Current File",
    "program": "${workspaceFolder}/node_modules/.bin/jest",
    "args": ["${relativeFile}"],
    "console": "integratedTerminal",
    "internalConsoleOptions": "neverOpen",
    "sourceMaps": true,
    "windows": {
          "program": "${workspaceFolder}/node_modules/jest/bin/jest",
    }
}

Also, using ts-jest like below did not change the outcome:

{
    "type": "node",
    "request": "launch",
    "name": "Jest Current File",
    "program": "${workspaceFolder}/node_modules/.bin/ts-jest",
    "args": ["${relativeFile}"],
    "console": "integratedTerminal",
    "internalConsoleOptions": "neverOpen",
    "sourceMaps": true,
    "windows": {
          "program": "${workspaceFolder}/node_modules/jest/bin/jest",
    }

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.