salesforce / sfdx-lwc-jest

Run Jest against LWC components in SFDX workspace environment
MIT License
165 stars 82 forks source link

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

Closed simon-nowak closed 1 year ago

simon-nowak commented 2 years ago

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

Additional context/Screenshots image

p3v9d5ui commented 2 years ago

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

ekashida commented 2 years ago

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

danielolaviobr commented 2 years ago

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

karencvaleriano commented 1 year ago

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

p3v9d5ui commented 1 year ago

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());
karencvaleriano commented 1 year ago

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