Skip to content

Add ability to await fireEvent #30

Closed
@EmilTholin

Description

@EmilTholin

As was outlined in this issue, you sometimes need to wait for the next microtask to run before changes in the DOM have been flushed.

const input = getByTestId('my-input');
fireEvent.input(input, {target: {value: 'some text'}});
// Wait for the next microtask for `value` to be 
// written to a potential bound variable
await tick();
// Check the value of the variable somehow

Maybe we could create a small abstraction over fireEvent from dom-testing-library and return a tick promise so that fireEvent can be awaited directly?

const input = getByTestId('my-input');
await fireEvent.input(input, {target: {value: 'some text'}});
// Check the value of the variable somehow
import {
  getQueriesForElement,
  prettyDOM,
  fireEvent as dtlFireEvent
} from '@testing-library/dom'
import { tick } from 'svelte'
export * from '@testing-library/dom'

export function fireEvent(...args) {
  dtlFireEvent(...args)
  return tick()
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions