Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does this still work in Jest? #5

Open
soulfresh opened this issue Jul 15, 2021 · 4 comments
Open

Does this still work in Jest? #5

soulfresh opened this issue Jul 15, 2021 · 4 comments
Labels
bug Something isn't working help wanted Extra attention is needed jest 🃏 https://jestjs.io/

Comments

@soulfresh
Copy link

This looks like a great tool but I've been unable to get it working with the latest version of Chrome. Is this project still supported/in use? If not, do you have some other way you've been debugging DOM elements in jsDom?

I've tried your setup steps and the manual test steps outlined in your development README but the formatter no longer recognizes HTML elements. The isElement() function never returns true for me when I run console.log(exampleNode) from the breakpoint in jest.test.js. Trying to debug that is a bit tricky since the console doesn't break on debugger statements in the header function.

I've noticed that the x parameter passed to the header function seems to be an object wrapping the console log arguments rather than the arguments themselves. I'm not sure if that's something weird with my setup.

// jest.test.js
  let exampleNode = document.getElementById("root");
  expect(exampleNode).toBeDefined();

  console.log(exampleNode);
  debugger;
  ...
// header.js
module.exports = x => {
  if (!isElement(x)) {
    console.log(
      'NOT AN ELEMENT', 
      typeof(x),  
      Object.keys(x), 
      x.exampleNode && x.exampleNode.nodeType
    ); // -->  NOT AN ELEMENT object [ 'exampleNode' ] 1

    // i.e. use normal formatter
    return null;
  }
  ...
}

As you can see, Object.keys(x) returns an object that has the key 'exampleNode' which is the HTMLElement to log.

Is this something strange with my environment? I'd love to get this working because it would be so helpful when debugging jest tests.

@viddo
Copy link
Collaborator

viddo commented Aug 22, 2021

Yes this does work in latest Chrome, but there appear to be an issue with Jest above v22 (which was what I used at the time of implementing/using this myself).

I suspect the introduction of custom console objects[1][2] might have something to do with it but would need to fork and modify jest source to verify that. Don't have the time to investigate further at this time, sorry.

Running your code outside the test environment in a normal NodeJS process could be a workaround I guess, but yeah it is not ideal to say the least.

@viddo viddo added bug Something isn't working help wanted Extra attention is needed jest 🃏 https://jestjs.io/ labels Aug 22, 2021
@soulfresh
Copy link
Author

Thanks for pointing that out, @viddo. I'll dig a bit on the Jest side to see what I can figure out.

@viddo
Copy link
Collaborator

viddo commented Dec 29, 2022

Better late than never I guess…

Updated internal tests and examples to use latest Jest and NodeJS, confirmed that it still works like before. Just had to update the manual test for Jest since configuration had some breaking changes. Original and published code v1.0.1 is still the same though. Published as v1.0.1, https://www.npmjs.com/package/jsdom-devtools-formatter

@viddo viddo closed this as completed Dec 29, 2022
@viddo
Copy link
Collaborator

viddo commented Dec 29, 2022

Reopening, as I was looking into #4 it seems like Jest integration is still borked. 😢
I'll edit the issue title to reflect contents of this thread.

@viddo viddo reopened this Dec 29, 2022
@viddo viddo changed the title Does this still work in Chrome 91? Does this still work in Jest? Dec 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed jest 🃏 https://jestjs.io/
Projects
None yet
Development

No branches or pull requests

2 participants