dperini / nwsapi

Fast CSS Selectors API Engine
MIT License
103 stars 35 forks source link

Fix the :has selector test #98

Closed alonidiom closed 10 months ago

alonidiom commented 10 months ago

Fixes https://github.com/jsdom/jsdom/pull/3609

blake-discover commented 10 months ago

I'm willing to help out further if needed. Perhaps add some missing test cases?

alonidiom commented 10 months ago

I couldn't' really wrap my head around how testing works here, but my PR for JSDOM includes a test that fails before the fix, and passes after it:

<style>
  .test-1, .test-2 {
    color: rgb(255, 0, 0);
  }
  /* ... */
  .test-2:has(span) {
    color: rgb(0, 255, 0);
  }
</style>
<div class="test-2">
    <p id="p2">test</p>
 </div>
<script>
  "use strict";

  // ...

  test(() => {
    const element = document.getElementById("p2");
    assert_equals(getComputedStyle(element).color, "rgb(255, 0, 0)");

    element.appendChild(document.createElement("span"));

    assert_equals(getComputedStyle(element).color, "rgb(0, 255, 0)");
  }, "Adding a span should change the text color to green");
</script>
blake-discover commented 10 months ago

@dperini, is there anything that's holding this PR back?

dperini commented 10 months ago

@alonidiom thank you for the contribution of the :has selector fix.