# Testing LWC with Jest and Visualforce controllers

*Platform Developer II Study Guide · Testing, Debugging, and Deployment · Last updated October 16, 2026 · https://www.certifyforce.com/study-guide/platform-developer-ii/testing-debugging-and-deployment/testing-lwc-with-jest-and-visualforce-controllers*

Write Jest tests for Lightning web components (async rendering, shadowRoot queries, mocked Apex, wire adapters, labels and events), debug JavaScript with Chrome DevTools and Jest debug mode, and test Visualforce controllers, extensions, page messages and continuations in Apex.

- Certification: Salesforce Platform Developer II
- Exam section: Testing, Debugging, and Deployment
- Study guide: https://www.certifyforce.com/study-guide/platform-developer-ii

**Official exam objective:**

> Apply techniques and tools for testing and debugging LWC, Aura Components, and Visualforce controllers and extensions, and JavaScript.

## What the exam expects

- Pick the right tool: Jest for Lightning web component JavaScript, Chrome DevTools for code running in the browser, Apex tests for Visualforce controllers and extensions.
- Read a Jest test and fix it: async rerendering, `element.shadowRoot` queries, mocked imperative Apex, wire adapter `emit()`/`error()`, custom label imports and event assertions.
- Debug JavaScript: pause on exceptions, custom formatters for proxies, Jest debug mode, and `this` inside callbacks.
- Test Visualforce controllers and extensions (`Test.setCurrentPage`, `ApexPages.StandardController`, `ApexPages.getMessages()`), find view-state hogs, and test continuation callbacks.

Key terms: **Jest** (the JavaScript test runner Salesforce recommends for LWC, run locally through `@salesforce/sfdx-lwc-jest`); **jsdom** (the simulated browser DOM Jest tests run against); **test wire adapter** (an sfdx-lwc-jest mock that pushes data or errors into a `@wire`); **custom formatter** (a DevTools console setting that shows the values inside LWC proxies); **controller extension** (an Apex class whose constructor takes one `ApexPages.StandardController` or custom controller).

## Key facts

| Fact | Detail | Source |
|---|---|---|
| Jest scope | Lightning web components only, not Aura; no browser or org | [Test Lightning Web Components](https://developer.salesforce.com/docs/platform/lwc/guide/testing.html) |
| Lightning Testing Service | Deprecated and no longer supported | [Testing Components (Aura)](https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/lightning_testing_intro.htm) |
| Test files | `__tests__` folder, not saved to Salesforce, listed in `.forceignore` | [Write Jest Tests for Lightning Web Components](https://developer.salesforce.com/docs/platform/lwc/guide/unit-testing-using-jest-create-tests.html) |
| jsdom | One instance per test file, not reset between tests | [Write Jest Tests for Lightning Web Components](https://developer.salesforce.com/docs/platform/lwc/guide/unit-testing-using-jest-create-tests.html) |
| Label imports in Jest | Resolve to the label path, such as `c.specialLabel` | [Jest Test Patterns and Mock Dependencies](https://developer.salesforce.com/docs/platform/lwc/guide/unit-testing-using-jest-patterns.html) |
| Wire adapter errors | Apex test wire adapter's `error()` emits an error | [Jest Testing Wire Service (Trailhead)](https://trailhead.salesforce.com/content/learn/modules/test-lightning-web-components/write-a-jest-test-for-wire-service) |
| Proxy values | Visible with DevTools custom formatters | [Debug Using Chrome DevTools](https://developer.salesforce.com/docs/platform/lwc/guide/debug-dev-tools.html) |
| Jest debug mode | `node --inspect-brk node_modules/.bin/jest --runInBand` | [Debug Jest Tests](https://developer.salesforce.com/docs/platform/lwc/guide/unit-testing-using-jest-debug-tests.html) |
| Extension constructor | Single argument: `ApexPages.StandardController` (or the custom controller it extends) | [Building a Controller Extension](https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_extension.htm) |
| View State tab | Needs `<apex:form>` and a custom controller or extension; 170KB limit | [Using the Development Mode Footer](https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_tools_edit_toolbar.htm) |

## Check yourself

- Why must a Jest test await a resolved promise after setting an `@api` property on an appended component?
- When does a wired component receive data emitted by a test wire adapter?
- Why does `this` become `undefined` in a regular `function` passed to `then()` inside a class method?
- How does a test create a controller extension for a record `p`?
- Which Apex call checks that a controller added an error message?

## Sources

- [Test Lightning Web Components](https://developer.salesforce.com/docs/platform/lwc/guide/testing.html)
- [Write Jest Tests for Lightning Web Components](https://developer.salesforce.com/docs/platform/lwc/guide/unit-testing-using-jest-create-tests.html)
- [Jest Test Patterns and Mock Dependencies](https://developer.salesforce.com/docs/platform/lwc/guide/unit-testing-using-jest-patterns.html)
- [Write Jest Tests for Wire Service](https://developer.salesforce.com/docs/platform/lwc/guide/unit-testing-using-wire-utility.html)
- [Jest Testing Wire Service (Trailhead)](https://trailhead.salesforce.com/content/learn/modules/test-lightning-web-components/write-a-jest-test-for-wire-service)
- [Debug Using Chrome DevTools](https://developer.salesforce.com/docs/platform/lwc/guide/debug-dev-tools.html)
- [Run Jest Tests](https://developer.salesforce.com/docs/platform/lwc/guide/unit-testing-using-jest-run-tests.html)
- [Debug Jest Tests](https://developer.salesforce.com/docs/platform/lwc/guide/unit-testing-using-jest-debug-tests.html)
- [Testing Components (Aura)](https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/lightning_testing_intro.htm)
- [Debugging (Aura)](https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/debug_intro.htm)
- [this (MDN)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this)
- [Arrow function expressions (MDN)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions)
- [Building a Controller Extension](https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_extension.htm)
- [StandardController Class](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_pages_standardcontroller.htm)
- [Test a Custom Controller](https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_error_handling.htm)
- [ApexPages Class](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_apexpages.htm)
- [Using the Development Mode Footer](https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_tools_edit_toolbar.htm)
- [Testing Asynchronous Callouts](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_continuation_testing.htm)

## About the full unit

The "Core concepts", "Exam traps" and "Worked scenario" sections of this unit, its 15 linked practice questions, and unlimited timed mock exams are included with the Platform Developer II pack (USD $19): https://www.certifyforce.com/practice-exams
