Sha256: f427ee1e0a3c8a69338ec2cabb73b56a38be6e198eda6be5a32aab7b4900a5e5

Contents?: true

Size: 994 Bytes

Versions: 13

Compression:

Stored size: 994 Bytes

Contents

import { updateComponent } from "./update-component";
import { describe, it, expect } from "vitest";

describe("updateComponent", () => {
  it("updates the component", () => {
    const component = document.createElement("div");
    component.innerHTML = `<div data-component="TestComponent" data-state='{"testAttribute": "initial"}'></div>`;

    const input = document.createElement("div");
    input.innerHTML = `<input value="updated" data-attribute="testAttribute">`;

    class TestComponent {
      state: any;
      constructor(state: any) {
        this.state = state;
      }
      get render() {
        return `<div>${this.state.testAttribute}</div>`;
      }
    };
    (window as any).TestComponent = TestComponent;

    updateComponent(
      component.firstChild as HTMLElement,
      JSON.parse(component.getAttribute("data-state") || "{}"),
      "testAttribute",
      input.firstChild as HTMLInputElement
    );

    expect(component.textContent).toBe("updated");
  });
});

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
clapton-0.0.13 lib/clapton/javascripts/src/dom/update-component.spec.ts
clapton-0.0.12 lib/clapton/javascripts/src/dom/update-component.spec.ts
clapton-0.0.11 lib/clapton/javascripts/src/dom/update-component.spec.ts
clapton-0.0.10 lib/clapton/javascripts/src/dom/update-component.spec.ts
clapton-0.0.9 lib/clapton/javascripts/src/dom/update-component.spec.ts
clapton-0.0.8 lib/clapton/javascripts/src/dom/update-component.spec.ts
clapton-0.0.7 lib/clapton/javascripts/src/dom/update-component.spec.ts
clapton-0.0.6 lib/clapton/javascripts/src/dom/update-component.spec.ts
clapton-0.0.5 lib/clapton/javascripts/src/dom/update-component.spec.ts
clapton-0.0.4 lib/clapton/javascripts/src/dom/update-component.spec.ts
clapton-0.0.3 lib/clapton/javascripts/src/dom/update-component.spec.ts
clapton-0.0.2 lib/clapton/javascripts/src/dom/update-component.spec.ts
clapton-0.0.1 lib/clapton/javascripts/src/dom/update-component.spec.ts