Suggested answer

LWC Jest tests use @salesforce/sfdx-lwc-jest. Structure: import { createElement } from 'lwc'; import MyComponent from 'c/myComponent'; describe('c-my-component', () => { afterEach(() => { while (document.body.firstChild) document.body.removeChild(document.body.firstChild); }); it('renders correctly', () => { const el = createElement('c-my-component', { is: MyComponent }); document.body.appendChild(el); expect(el.shadowRoot.querySelector('h1').textContent).toBe('Hello'); }); });. Mocking @wire: Import registerApexTestWireAdapter from @salesforce/sfdx-lwc-jest. Mock the wire: const adapter = registerApexTestWireAdapter(getRecord); adapter.emit(mockData);. Mocking Apex: jest.mock('@salesforce/apex/AccountCtrl.getAccounts', () => jest.fn(), { virtual: true }); getAccounts.mockResolvedValue(mockData);. Test events by spying on dispatchEvent.

Practice content for interview preparation; not an official vendor answer. Verify details against current product documentation.

Community comments (0)

No comments yet.

Sign in or create a free account to add a comment. Comments are moderated before they appear.

Plain text only, 3–2000 characters. A moderator reviews every comment before it is published.