Skip to content

Does this still work in Jest? #5

@soulfresh

Description

@soulfresh

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is neededjest 🃏https://jestjs.io/

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions