2

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?

2 Answers 2

2

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.

0

I also ran into this when trying to update mocks of wireAdapters.

The cause I ended up finding for TypeError: Invalid adapterId, it must be extensible. is that there was another wireAdapter on my main class needed to be mocked as well. I ended up putting a console log on the node_modules class that was throwing the error to find which wire.

I hope this can help anyone who runs into this same error code.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .