My lwc has an input and a button. When I press the button an apex call with the input's value is made. Even though the method is called with the right params, the return value is some sort of empty object
const APEX_OBJECTS_LIST = require("./data/objectsList.json");
jest.mock(
"@salesforce/apex/ObjectController.findObject",
() => {
return { default: jest.fn() };
},
{ virtual: true }
);
async function flushPromises() {
return Promise.resolve();
}
---
findObject.mockResolvedValue(APEX_OBJECTS_LIST);
const buttonEl = element.shadowRoot.querySelector("lightning-button");
buttonEl.click();
await flushPromises();
expect(findObject).toHaveBeenCalledWith({ searchKey: "OBJ-123456" });
expect(findObject).toHaveReturnedWith(APEX_OBJECTS_LIST);
# Error
expect(jest.fn()).toHaveReturnedWith(expected)
Expected: APEX_OBJECTS_LIST
Received: {}
The most helpful answer I found was from this question. I also test other tags that are populated with the mocked list and they are successful. This means that the mocked object does come through but is not "cough" at toHaveReturnedWith()
.
If I try toHaveReturnedWith({})
the error is the same, meaning that what is received is not an empty object after all.