sfdx-lwc-jest icon indicating copy to clipboard operation
sfdx-lwc-jest copied to clipboard

Cannot run JEST unit test on “getRelatedListRecords” from uiRelatedListApi.

Open simon-nowak opened this issue 2 years ago • 3 comments

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 image

simon-nowak avatar Jul 21 '22 13:07 simon-nowak

Any resolution for this? This is blocking me as well.

p3v9d5ui avatar Jul 26 '22 13:07 p3v9d5ui

@Templarian looks like this stub is generated for core but not for platform.

ekashida avatar Jul 27 '22 16:07 ekashida

@ekashida Are there any updates for this? I've updated to 1.1.2 and I'm still getting the same error

danielolaviobr avatar Aug 23 '22 11:08 danielolaviobr

Hi, I'm also getting the same error. Is there already a fix on this? I used the 1.1.3 version. Thank you.

karencvaleriano avatar Nov 08 '22 03:11 karencvaleriano

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());

p3v9d5ui avatar Nov 08 '22 10:11 p3v9d5ui

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!!!

karencvaleriano avatar Nov 09 '22 01:11 karencvaleriano