Skip to content

The dispatchEvent function is added as a test utility

Compare
Choose a tag to compare
@UpperCod UpperCod released this 20 Aug 04:19
· 84 commits to master since this release

The dispatchEvent function is intended to facilitate component testing, allowing you to dispatch events from an event and customize its target, example:

import { fixture, asyncEventListener, dispatchEvent } from "atomico/test-dom";

test("check target", async () => {
  const myComponent = fixture(<MyComponent />);
  const eventName = "myEvent";

  queueMicrotask(() => {
    const target = { value: 1000 };
    const event = new Event(eventName);
    dispatchEvent(myComponent, event, target);
  });

  const event = await asyncEventListener(myComponent, eventName);

  expect(event.target).toEqual({ value: 1000 });
});