cockpit-plugin-base-react - v1.1.1
    Preparing search index...

    Function mockCockpitFile

    • Creates a fake cockpit.file() return value.

      Parameters

      • content: string | null

        Initial file content. Pass null to simulate a missing file (ENOENT).

      • Optionalerror: string

        When provided, read() and replace() reject with this message.

      Returns {
          read(): Promise<string | null>;
          replace(content: string): Promise<void>;
          watch(callback: (content: string | null) => void): CockpitChannel;
      }

      vi.spyOn(cockpit, "file").mockReturnValue(mockCockpitFile("[Unit]\nDescription=test\n"));
      vi.spyOn(cockpit, "file").mockReturnValue(mockCockpitFile(null)); // missing file