Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to debug test case using Jest in chrome under node devTools

enter image description hereI just started using Jest. For debugging under testcase file;

  describe("Filter function", () => {
  test("it should filter by a search", () => {
    const input = [
      { id: 1, url: "https://www.google.com" },
      { id: 2, url: "https://www.yahoo.com" },
      { id: 3, url: "https://www.gmail.com" }
    ];

    const output = [{ id: 3, url: "https://www.gmail.com" }];
    debugger;
    expect(filterByTerm(input, "gmail")).toEqual(output);
    debugger;
    expect(filterByTerm(input, "GMAIL")).toEqual(output);
  });

 
});

under Project directory - run this command

node --inspect-brk ./node_modules/jest/bin/jest.js --runInBand

After running this command says node --inspect-brk node_modules/jest/bin/jest.js --runInBand Debugger listening on ws://127.0.0.1:9229/ab651461-dfe8-4528-8a07-484a4be5db7b For help, see: https://nodejs.org/en/docs/inspector

after this opened chrome://inspect under it clicked on open dedicated devtools for Node here, It opened window where I added src folder for same and opened test file but debugging didnt came. Help please on same issue

enter image description here However, in the resulting dev tools window, I can't see anything to debug. I am expecting a process where I can set breakpoints and inspect data.

like image 685
Swift Avatar asked Aug 27 '26 19:08

Swift


1 Answers

Run this command;

node --inspect-brk ./node_modules/jest/bin/jest.js --runInBand
Debugger listening on ws://127.0.0.1:9229/6a0bb29e-eca2-4a25-b894-a5e803339ec9
For help, see: https://nodejs.org/en/docs/inspector

After this enter this url in chrome;

devtools://devtools/bundled/inspector.html?experiments=true&v8only=true&ws=127.0.0.1:9229/6a0bb29e-eca2-4a25-b894-a5e803339ec9

and Resume the button on right hand side again Press again F8 wait for some time, Debugging started Like charm..! on your test file where debugger; is written

Thank you again ! enter image description here

like image 76
Swift Avatar answered Aug 29 '26 10:08

Swift



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!