Skip to content

Simulate events returning promises? #823

@jdgreenberger

Description

@jdgreenberger

Hi there - really enjoying the library! I have a question about testing simulate events. Many of the events in my code trigger functions that wait for promises.

onClick = async (e) => {
   data = await fetchData(e.target.value)
   this.setState({data})
}

In the live react, events clearly don't return promises, but I'm not sure if enzyme's simulate is also event-driven. Is there a way that I can wait for a simulate event to return a promise? I know there is an alternative, but it's a little bit more overhead.

someFunc = async () => {
  data = await fetchData(e.target.value)
   this.setState({data})
}
onClick = (e) => {
   someFunc()
}
// test onClick calls someFunc()
// test someFunc()

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions