Test Lightning Web Components

Jest is a powerful tool with rich features for writing JavaScript tests. Use Jest to write unit tests for all of your Lightning web components.

Run Jest tests at the command line or (with some configuration) within your IDE. Jest tests don’t run in a browser or connect to an org, so they run fast. When run in “watch mode” they give you immediate feedback while you’re coding. Jest tests work only with Lightning web components, they don’t work with Aura components.

Write Jest tests to:

  • Test a component in isolation
  • Test a component’s public API (@api properties and methods, events)
  • Test basic user interaction (clicks)
  • Verify the DOM output of a component
  • Verify that events fire when expected

The lwc-recipes repo is filled with Jest tests. Look for Jest tests in the __tests__ folders within the Lightning web components in force-app/main/default/lwc.

See Also