79789291

Date: 2025-10-13 12:54:46
Score: 1
Natty:
Report link

I actually managed to figure this out. Apparently my first try was almost correct:

vi.mock("@/composables/ApiClient", () => ({
    useApiClient: () => ({
        apiClient // from the previous codeblock
    })
}));

But instead of using the apiClient const, I needed to actually write everything open.

vi.mock("@/composables/ApiClient", () => ({
    useApiClient: () => ({
        apiClient: {
            getSafe: vi.fn(() => ({
                response: {
                    data: {
                        someData: "something",
                        otherData: "somethingElse"
                    }
                }
            }))
        }
    })
}));

Doing it this way the mock started to work. It looks horrible and I wish I could use some variables to make this look nice, but I guess it can't be helped.

Reasons:
  • Blacklisted phrase (0.5): I need
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Vampuuri