Skip to content
This repository has been archived by the owner on May 30, 2023. It is now read-only.

[DO NOT MERGE] Failed test #61

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"fields": {
"Name": {
"value": "DYNAMO X1"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {
createElement
} from 'lwc';
import {registerLdsTestWireAdapter} from '@salesforce/sfdx-lwc-jest';
import ProductCard from '../productCard'; // updated - grabbing locally instead of c/productCard - not extensible
import {getRecord} from 'lightning/uiRecordApi'; //<-- problem - THIS is not extensible



// Import mock data to send through the wire adapter.
const mockGetRecord = require('./getRecord.json');

// Register a test wire adapter. - 2.0 way!
const getRecordWireAdapter = registerLdsTestWireAdapter(getRecord);

describe('@wire demonstration test', () => {
// Disconnect the component to reset the adapter. It is also
// a best practice to clean up after each test.
afterEach(() => {
while (document.body.firstChild) {
document.body.removeChild(document.body.firstChild);
}
});

it('displays product name field', () => {
const element = createElement('c-product_filter', {
is: ProductCard
});
document.body.appendChild(element);
getRecordWireAdapter.emit(mockGetRecord);

// Resolve a promise to wait for a rerender of the new content.
return Promise.resolve().then(() => {
const content = element.shadowRoot.querySelector('.content');
const nameField = mockGetRecord.fields.Name.value;
expect(content.textContent).toBe(`Name:${nameField}`); // both not null

});
});
});
11 changes: 11 additions & 0 deletions force-app/main/default/lwc/productCard/productCard.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- productCard.html -->
<template>
<div class="content">
<template if:true={product}>
<div class="name">
<div>Name:</div>
<div>{name}</div>
</div>
</template>
</div>
</template>
23 changes: 23 additions & 0 deletions force-app/main/default/lwc/productCard/productCard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { LightningElement, wire } from 'lwc';

// Wire adapter to load records.
import { getRecord } from 'lightning/uiRecordApi';

export default class ProductCard extends LightningElement {
// Id of Product__c to display.
recordId;

// Product__c to display //
product;

// Product__c field values to display. //
name = '';

@wire(getRecord, { recordId: '$recordId', fields })
wiredRecord({ data }) {
if (data) {
this.product = data;
this.name = data.fields.Name.value;
}
}
}
2 changes: 1 addition & 1 deletion sfdx-project.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
],
"namespace": "",
"sfdcLoginUrl": "https://login.salesforce.com",
"sourceApiVersion": "50.0"
"sourceApiVersion": "51.0"
}