4

How exactly do we mock getRecordNotifyChange in a JEST test? I cannot find an example anywhere.

1 Answer 1

1

The stub provided with lwc-jest for uiRecordApi doesn't seem to include a mock function for that specifically so you'll have to create your own. Considering getRecordNotifyChange returns void, you don't have to worry about any sort of expected result.

You can store it in a directory of lwc/__tests__/lightning and call it uiRecordApi. It'll be the same as the stub linked above except with an included mock function return for getRecordNotifyChange

export const getRecordNotifyChange = jest.fn();

Then, you'll want to update jest.config.js to use your stub you created above for the uiRecordApi module. You'll add the relevant mapping under moduleNameMapper

moduleNameMapper: {
    '^lightning/uiRecordApi$':
        '<rootDir>/force-app/test/jest-mocks/lightning/uiRecordApi
},

Then, in your jest test, just import the module (which'll use your stub from the mapping you created above)

import { getRecordNotifyChange } from "lightning/uiRecordApi"

You must log in to answer this question.

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