79472148

Date: 2025-02-27 09:20:28
Score: 1
Natty:
Report link

Apparently, I can just do it like this:

const { mockUseNuxtApp } = vi.hoisted(() => ({
    mockUseNuxtApp: vi.fn(() => ({
        $csrfFetch: vi.fn(),
    })),
}));

mockNuxtImport('useNuxtApp', () => mockUseNuxtApp);

describe('...', () => {
    afterEach(() => {
        mockFetch.mockReset();
    });
    it('...', async () => {
      mockUseNuxtApp.mockReturnValue({
          $csrfFetch: vi.fn(),
      });
      
      // do somthing where $csrfFetch is used
      
    });
});

Reasons:
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: L1nux