Loading tutorials
npm run test:unit in a Salesforce DX project, as set up in the previous chapter. It also assumes you know basic JavaScript functions, arrow functions, and promises. You will learn how a Jest test file is organized, how hooks run, and which structural mistakes cause5 min readsfdx-lwc-jest and know the basic describe, it, and expect structure. It also assumes you know LWC fundamentals: templates, @api properties, and lifecycle hooks. Here you will learn how a test creates a component, attaches it to a docu6 min readcreateElement and attach it to document.body. You should know how a Lightning web component template renders for:each and conditional blocks. The goal is to find the el4 min readcreateElement and finds elements through shadowRoot. It also assumes you are comfortable with promises and async/await. The counter component from the setup chapter is used again here.5 min readcreateElement, query its shadow root, and wait for re-rendering with await Promise.resolve(). It also ass6 min read@api properties and methods. Parent components and tests reach the component only through that API, so tests of it describe the contract the component promises.4 min readconnectedCallback or a click handler. Jest tests run in Node.js without a Salesforce org, so there is no Apex to call. You replace the Apex import with a controllable fake. This 5 min readcreateElement, query its shadow root, and wait one microtask before asserting. It also assumes you have mocked an imperative Apex call with a virtual jest.mock. If any of that is unfamiliar, review the earlier chapters first.4 min readlightning-button, and your own child components such as c-contact-card. It assumes you can already create a component with createElement, query its shadow 5 min read@salesforce/label/..., @salesforce/user/Id, lightning/navigation, and lightning/platformShowToastEvent. Jest runs in Node, outside an org, so it cannot load them directly. This chapter shows how `sfdx-lwc5 min readcreateElement, query the shadow root, and await re-rendering. It also assumes the sfdx-lwc-jest setup from the earlier chapters. Here you will learn how to find code your tests never run, how to e6 min read