You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: expose new methods from @salesforce/wire-service-jest-util (#227)
* docs: copyedit readme and remove sample code based on wire reform (#204)
* docs: copyedit and remove code based on wire reform
* docs: run yarn format
* fix: expose new methods from @salesforce/wire-service-jest-util (#207)
* chore: update lightning stubs (#206)
Co-authored-by: Jody Bleyle <[email protected]>
Copy file name to clipboardExpand all lines: README.md
+7-15Lines changed: 7 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -89,7 +89,7 @@ sfdx-lwc-jest -- --json
89
89
90
90
See the [Jest documentation](http://facebook.github.io/jest/docs/en/cli.html) for all CLI options.
91
91
92
-
## Debug mode
92
+
## Debug Mode
93
93
94
94
Debug mode lets you easily debug your Jest tests.
95
95
@@ -135,7 +135,7 @@ If you prefer to debug inside Visual Studio Code, follow these steps:
135
135
- Add a `jest.config.js` file to the root of the Salesforce DX project as described [here](#overriding-jest-config). You must add this file to run Jest from Visual Studio Code.
136
136
- To run tests, press F5 or select Debug > Start Debugging.
137
137
138
-
## Watch mode
138
+
## Watch Mode
139
139
140
140
Watch mode causes Jest to monitor files for changes and rerun tests related to the changed files. This is a great way to rapidly make component and test changes while monitoring tests results.
141
141
@@ -163,17 +163,17 @@ This package installs stubs for the `lightning` base components to the `src/ligh
163
163
164
164
For components from other namespaces, not in your local `lwc` directory, create your own mock and update the Jest config to map the name of these components to the mock file.
165
165
166
-
Let's go through an example. Given the following template, `helloWorld.html`, we want to test:
166
+
Let's go through an example. We want to test the following template, `helloWorld.html`.
Because it's in the `lightning` namespace, the `lightning-button` just works. However, you must write some code to help the Jest resolver find the `foo-fancy-button component`. First, create a `jest.config.js` file at the root of the Salesforce DX project workspace and add the following:
176
+
Because it's in the `lightning` namespace, the `lightning-button` just works. However, you must write some code to help the Jest resolver find the `foo-fancy-button` component. First, create a `jest.config.js` file at the root of the Salesforce DX project workspace and add the following:
This tells Jest to map the import for `foo-fancy-button` to the provided file. Notice that the first dash is converted to a forward slash and the rest of the component name goes from kebab to camel case. The reason for the forward slash is because the module resolver treats everything before the first dash as the namespace. Here, `<rootDir>` maps to the root of the Salesforce DX workspace. Note that this file location is not required, just an example.
188
+
This config tells Jest to map the import for `foo-fancy-button` to the provided file. Notice that the first dash is converted to a forward slash and the rest of the component name goes from kebab to camel case. The reason for the forward slash is because the module resolver treats everything before the first dash as the namespace. Here, `<rootDir>` maps to the root of the Salesforce DX workspace. Note that this file location is not required, just an example.
189
189
190
190
You also have the freedom to make these mock implementations as sophisticated or simple as you'd like. In this example, we'll keep `foo-fancy-button` simple with an empty template and no functionality in the `.js` file, but you can always add whatever markup you'd like or implement functionality like any other Lightning web component.
To provision data through `@wire` adapters in unit tests, use the APIs provided by [`@salesforce/wire-service-jest-util`](https://github.com/salesforce/wire-service-jest-util). These APIs are exposed through this package so you do not need to include another dependency in your package.json.
211
211
212
-
```js
213
-
import {
214
-
registerTestWireAdapter,
215
-
registerLdsTestWireAdapter,
216
-
registerApexTestWireAdapter,
217
-
} from'@salesforce/sfdx-lwc-jest';
218
-
```
219
-
220
212
See the `@salesforce/wire-service-jest-util`[README](https://github.com/salesforce/wire-service-jest-util/blob/master/README.md) for further documentation on these APIs.
0 commit comments