Untested Lightning Web Components
Why is this an issue?
Lightning Web Components without test coverage are more likely to contain bugs and regressions. Untested components are harder to refactor safely and may not behave correctly across different scenarios.
This rule identifies LWC controllers (JavaScript files) that do not have corresponding test files that import and test them.
Examples
Example of incorrect configuration:
force-app/main/default/lwc/myComponent/
myComponent.js # No tests import this component
myComponent.html
Example of correct configuration:
force-app/main/default/lwc/myComponent/
myComponent.js
myComponent.html
__tests__/
myComponent.test.js # Imports and tests 'c/myComponent'
The test file must import the component using the c/ prefix:
import MyComponent from 'c/myComponent';
How can I fix violations?
Create a
__tests__directory inside your LWC bundleCreate a test file (e.g.,
myComponent.test.js)Import your component using the standard
c/componentNameimport syntaxWrite meaningful tests that cover your component's functionality
When should I disable this rule?
You may want to dismiss this issue if:
The component is a trivial wrapper component with no logic or state
The component is being deprecated and will be removed soon
You have integration tests that cover the component's functionality at a higher level
Resources
