sfdx-lwc-jest
sfdx-lwc-jest copied to clipboard
Cannot run JEST unit test on “getRelatedListRecords” from uiRelatedListApi.
Description
Hello here,
I’m working on a LWC component that use the “getRelatedListRecords” from uiRelatedListApi. It’s working fine on my orgs. This UI API has been introduced with the salesforce v54.
My problem is about the JEST unit test. The error message is about the “getRelatedListRecords”. This module cannot be found.
I have the last version of “@ salesforce/sfdx-lwc-jest”: “^1.1.0" If I understand well this version is running the v53.
I took a look at the package documentation and found a reference to “prerelease”. But I don’t find any “prerelease” anywhere. And the “last” version is still the 1.1.0.
Does anyone know what are my solutions/workarounds here?
Steps to Reproduce
// simplified test case
it('shows error panel when wire return error', () => {
const element = createElement('c-xxxx', {
is: xxxx
});
document.body.appendChild(element);
// Emit error from @wire
getRelatedListRecords.error();
return Promise.resolve().then(() => {
const errorElement = element.shadowRoot.querySelector('c-error-panel');
expect(errorElement).not.toBeNull();
});
});
<!-- HTML for component under test -->
<template> </template>
// JS for component under test
import { LightningElement } from 'lwc';
import { getRelatedListRecords } from 'lightning/uiRelatedListApi';
export default class xxxx extends LightningElement {}
# Command to repro
sfdx-lwc-jest
Expected Results
Runing the test.
Instead I have thoses errors (see more in screenshot)
error Invalid sourceApiVersion found in sfdx-project.json. Expected 53.0, found 55.0 Cannot find module 'lightning/uiRelatedListApi' from 'tradespeople-approval-acquisition/main/default/lwc/xxxx/xxxx.js'
Version
- @salesforce/sfdx-lwc-jest: 1.1.0
- Node: 14.15.5
Additional context/Screenshots
Any resolution for this? This is blocking me as well.
@Templarian looks like this stub is generated for core but not for platform.
@ekashida Are there any updates for this? I've updated to 1.1.2
and I'm still getting the same error
Hi, I'm also getting the same error. Is there already a fix on this? I used the 1.1.3
version. Thank you.
I created a mock for this as: force-app/test/jest-mocks/lightning/uiRelatedListApi.js
, which contains:
import { createLdsTestWireAdapter } from '@salesforce/wire-service-jest-util';
export const getRelatedListRecords = createLdsTestWireAdapter(jest.fn());
I created a mock for this as:
force-app/test/jest-mocks/lightning/uiRelatedListApi.js
, which contains:import { createLdsTestWireAdapter } from '@salesforce/wire-service-jest-util'; export const getRelatedListRecords = createLdsTestWireAdapter(jest.fn());
thanks @p3v9d5ui , it worked!!!