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?


Okay so it turns out it has nothing to do with the 'getRecordNotifyChange' itself, there was another issue in the test that was causing it to fail. For some reason, it was reporting this weird error. I wrapped the getRecordNotifyCall under a method in another helper class, and mocked that method using jest.fn(). That seems to be working okay. Posting in case someone runs into this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.