Skip to content

Instantly share code, notes, and snippets.

@bcherny
Created February 6, 2019 00:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bcherny/00dd36c7a53a45dba53a929dcc30c992 to your computer and use it in GitHub Desktop.
Save bcherny/00dd36c7a53a45dba53a929dcc30c992 to your computer and use it in GitHub Desktop.
let called = false;
// this 'scope' is safe to interact with the React component,
// rendering and clicking as you please
await render(
<App
callback={() => {
called = true;
}}
/>,
document.body
);
// at this point, we can guarantee that effects have been executed,
// so we can make assertions
expect(called).toBe(true); // this passes now!
const button = document.getElementById('button');
await dispatchEvent(button, new MouseEvent('click', {bubbles: true}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment