<commit_before><commit_msg>Add regression test for dynamic <style> updates<commit_after><!DOCTYPE html>
<meta charset="utf-8">
<title>Updating the textContent of a style element must change the results of getComputedStyle</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<!-- Derived from https://github.com/jsdom/jsdom/issues/2292 -->

<style>
  .my-class {
    font-size: 1.5em;
  }
</style>

<h1 class="my-class">Hello world</h1>

<script>
"use strict";
const el = document.querySelector(".my-class");
let insertedStyle;

test(() => {
  assert_equals(getComputedStyle(el).fontSize, "1.5em");
}, "Sanity check: getComputedStyle works as expected");

test(() => {
  insertedStyle = document.createElement("style");
  insertedStyle.textContent = ".my-class { font-size: 2em; }";
  document.head.appendChild(insertedStyle);

  assert_equals(getComputedStyle(el).fontSize, "2em");
}, "Inserting a new CSS element that overrides the old one updates the computed style");

test(() => {
  insertedStyle.textContent = ".my-class { font-size: 3em; }";

  assert_equals(getComputedStyle(el).fontSize, "3em");
}, "Updating the inserted CSS element changes the computed style");
</script>
{'fraction_non_alphanumeric': 0.1607717041800643, 'fraction_numerical': 0.012057877813504822, 'mean_word_length': 5.384615384615385, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 22, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4158114', 'n_tokens_mistral': 401, 'n_tokens_neox': 393, 'n_words': 96}