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");

  () => {
    return { default: jest.fn() };
  { virtual: true }

async function flushPromises() {
  return Promise.resolve();
const buttonEl = element.shadowRoot.querySelector("lightning-button");

await flushPromises();

expect(findObject).toHaveBeenCalledWith({ searchKey: "OBJ-123456" });
# Error

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.

1 Answer 1


The jest documentation has a .resolves/.rejects testing section. Testing this out, it seems the resolves.toBe() can help you assert that your resolved promise is what you provided


If the above were to fail, you'll notice the following would be the error

JestAssertionError: expect(received).resolves.toBe(expected)

Looking at your error message, you can see it's referencing the mock implementation: jest.fn().

You must log in to answer this question.

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