Skip to content

Conversation

@codeart1st
Copy link
Contributor

In unit tests without .peek() or .get(), we encountered many exceptions due to the behavior of vitest and chai when iterating over objects for equality checks and error printing. Making this more resilient without throwing exceptions seems like a useful improvement for me.

@jmeistrich
Copy link
Member

Looking into this I think it needs a bit more logic to handle functions. What do you think of something like this? It would also be cool if you want to add some tests like you did in your other PRs :). We could use more tests to make sure this is correct.

has(node: NodeInfo, prop: string | symbol) {
      const value = getNodeValue(node);

      // Short-circuit for the inputs that make Reflect.has error.
      if (value === undefined || value === null) {
          return false;
      }

      // Functions behave like objects here, so let them flow through.
      if (typeof value === 'object' || typeof value === 'function') {
          return Reflect.has(value, prop);
      }

      // For primitives (number, string, boolean, bigint, symbol) report “no key”.
      // That keeps inspection code happy without pretending properties exist.
      return false;
  }

@codeart1st
Copy link
Contributor Author

I dive into the problem again and extract the essential parts as a unit test. I also add another needed change to get @vitest/pretty-format working with constructor.name calls.

@codeart1st
Copy link
Contributor Author

@jmeistrich this also needs your attention again.

@codeart1st
Copy link
Contributor Author

@jmeistrich weekly reminder

@codeart1st
Copy link
Contributor Author

@jmeistrich gentle weekly reminder

@jmeistrich
Copy link
Member

@codeart1st I pushed a small commit to tweak that constructor behavior so if the wrapped object has a constructor it returns that before creating a new one. Does that seem reasonable to you?

@codeart1st
Copy link
Contributor Author

@jmeistrich looks very reasonable to me. Nice addition.

codeart1st and others added 3 commits December 2, 2025 16:22
In unit tests without .peek() or .get(), we encountered many exceptions due to the behavior of vitest and chai when iterating over objects for equality checks and error printing. Making this more resilient without throwing exceptions seems like a useful improvement for me.
@codeart1st codeart1st requested a review from jmeistrich December 2, 2025 16:40
@jmeistrich jmeistrich merged commit 8b7617b into LegendApp:main Dec 4, 2025
3 checks passed
@codeart1st codeart1st deleted the has-trap-resilient branch December 4, 2025 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants