Skip to main content
1 of 2

LWC jest issue with getRecordNotifyChange - TypeError: (0 , _uiRecordApi.getRecordNotifyChange) is not a function

I am using 'getRecordNotifyChange'https://developer.salesforce.com/docs/component-library/documentation/en/lwc/reference_get_record_notify in a "Modify" LWC component, to flag a record as having been updated outside of the LDS framework (via API call). The functionality works, however, adding the line to call getRecordNotifyChange to the JS file of the LWC component throws the Jest unit tests off with the following error:

TypeError: (0 , _uiRecordApi.getRecordNotifyChange) is not a function

I tried using the registerLdsTestWireAdapter for mocking like we do for the wired getRecord method but that gives the following error

No adapter specified

       | const getRecordAdapter = registerLdsTestWireAdapter(getRecord);
       | 
    >  | const getRecordNotifyChangeAdapter = registerLdsTestWireAdapter(getRecordNotifyChange);
       |                                      ^

Another option I tried is below

jest.mock('lightning/uiRecordApi', () => {
    return jest.fn().mockImplementation(() => {
        return {
            getRecordNotifyChange: function (recordIds) {
                return {};
            }
        }
    })
});

But this gives the following error:

TypeError: Invalid adapterId, it must be extensible.

I couldn't find Salesforce documentation around this, and didn't come across anything in the LWC recipes on GitHub, at least where I looked.

Has anyone else run into this? Looking for suggestions on what I can try here?