Skip to content

Commit 2b21733

Browse files
jodarovejbleyleSF
andauthored
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]>
1 parent 0cc034d commit 2b21733

File tree

22 files changed

+109
-25
lines changed

22 files changed

+109
-25
lines changed

README.md

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ sfdx-lwc-jest -- --json
8989

9090
See the [Jest documentation](http://facebook.github.io/jest/docs/en/cli.html) for all CLI options.
9191

92-
## Debug mode
92+
## Debug Mode
9393

9494
Debug mode lets you easily debug your Jest tests.
9595

@@ -135,7 +135,7 @@ If you prefer to debug inside Visual Studio Code, follow these steps:
135135
- 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.
136136
- To run tests, press F5 or select Debug > Start Debugging.
137137

138-
## Watch mode
138+
## Watch Mode
139139

140140
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.
141141

@@ -163,17 +163,17 @@ This package installs stubs for the `lightning` base components to the `src/ligh
163163

164164
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.
165165

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`.
167167

168168
```html
169169
<template>
170170
Hello From a Lightning Web Component!
171-
<lightning-button onclick={doSomething}></lightning-button>
172-
<foo-fancy-button onclick={doSomethingElse}></foo-button>
171+
<lightning-button onclick="{doSomething}"></lightning-button>
172+
<foo-fancy-button onclick="{doSomethingElse}"></foo-fancy-button>
173173
</template>
174174
```
175175

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:
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:
177177

178178
```js
179179
const { jestConfig } = require('@salesforce/sfdx-lwc-jest/config');
@@ -185,7 +185,7 @@ module.exports = {
185185
};
186186
```
187187

188-
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.
189189

190190
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.
191191

@@ -209,12 +209,4 @@ export default class FancyButton extends LightningElement {
209209

210210
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.
211211

212-
```js
213-
import {
214-
registerTestWireAdapter,
215-
registerLdsTestWireAdapter,
216-
registerApexTestWireAdapter,
217-
} from '@salesforce/sfdx-lwc-jest';
218-
```
219-
220212
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.

src/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,18 @@
77
'use strict';
88

99
const {
10+
createApexTestWireAdapter,
11+
createLdsTestWireAdapter,
12+
createTestWireAdapter,
1013
registerLdsTestWireAdapter,
1114
registerApexTestWireAdapter,
1215
registerTestWireAdapter,
1316
} = require('@salesforce/wire-service-jest-util');
1417

1518
module.exports = {
19+
createApexTestWireAdapter,
20+
createLdsTestWireAdapter,
21+
createTestWireAdapter,
1622
registerLdsTestWireAdapter,
1723
registerApexTestWireAdapter,
1824
registerTestWireAdapter,
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (c) 2021, salesforce.com, inc.
3+
* All rights reserved.
4+
* SPDX-License-Identifier: MIT
5+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6+
*/
7+
import { createLdsTestWireAdapter } from '@salesforce/wire-service-jest-util';
8+
9+
export const createDataflowJob = jest.fn();
10+
export const deleteDataset = jest.fn();
11+
export const deleteRecipe = jest.fn();
12+
export const executeQuery = createLdsTestWireAdapter(jest.fn());
13+
export const getAnalyticsLimits = createLdsTestWireAdapter(jest.fn());
14+
export const getDataflowJob = createLdsTestWireAdapter(jest.fn());
15+
export const getDataflowJobNode = createLdsTestWireAdapter(jest.fn());
16+
export const getDataflowJobNodes = createLdsTestWireAdapter(jest.fn());
17+
export const getDataflowJobs = createLdsTestWireAdapter(jest.fn());
18+
export const getDataset = createLdsTestWireAdapter(jest.fn());
19+
export const getDatasets = createLdsTestWireAdapter(jest.fn());
20+
export const getRecipe = createLdsTestWireAdapter(jest.fn());
21+
export const getRecipes = createLdsTestWireAdapter(jest.fn());
22+
export const getReplicatedDatasets = createLdsTestWireAdapter(jest.fn());
23+
export const getSchedule = createLdsTestWireAdapter(jest.fn());
24+
export const getWaveFolders = createLdsTestWireAdapter(jest.fn());
25+
export const getXmd = createLdsTestWireAdapter(jest.fn());
26+
export const updateDataflowJob = jest.fn();
27+
export const updateSchedule = jest.fn();

src/lightning-stubs/combobox/combobox.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import { LightningElement, api } from 'lwc';
88

99
export default class Combobox extends LightningElement {
10+
@api autocomplete;
1011
@api disabled;
1112
@api dropdownAlignment;
1213
@api fieldLevelHelp;

src/lightning-stubs/datatable/datatable.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export default class Datatable extends LightningElement {
2222
@api maxColumnWidth;
2323
@api maxRowSelection;
2424
@api minColumnWidth;
25+
@api renderConfig;
2526
@api resizeColumnDisabled;
2627
@api resizeStep;
2728
@api rowNumberOffset;

src/lightning-stubs/formattedPhone/formattedPhone.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
import { LightningElement, api } from 'lwc';
88

99
export default class FormattedPhone extends LightningElement {
10+
@api disabled;
1011
@api value;
1112
}

src/lightning-stubs/helptext/helptext.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import { LightningElement, api } from 'lwc';
88

99
export default class Helptext extends LightningElement {
10+
@api alternativeText;
1011
@api content;
1112
@api iconName;
1213
@api iconVariant;

src/lightning-stubs/input/input.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ export default class Input extends LightningElement {
4343
@api placeholder;
4444
@api readOnly;
4545
@api required;
46+
@api selectionEnd;
47+
@api selectionStart;
4648
@api step;
4749
@api timeAriaControls;
4850
@api timeAriaDescribedBy;

src/lightning-stubs/inputAddress/inputAddress.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export default class InputAddress extends LightningElement {
1313
@api cityLabel;
1414
@api cityPlaceholder;
1515
@api country;
16+
@api countryDisabled;
1617
@api countryLabel;
1718
@api countryOptions;
1819
@api countryPlaceholder;

src/lightning-stubs/inputRichText/inputRichText.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export default class InputRichText extends LightningElement {
1010
@api customButtons;
1111
@api disabled;
1212
@api disabledCategories;
13+
@api fieldLevelHelp;
1314
@api formats;
1415
@api label;
1516
@api labelVisible;

0 commit comments

Comments
 (0)