containers / podman-desktop-extension-ai-lab

Work with LLMs on a local environment using containers
https://podman-desktop.io/extensions/ai-lab
Apache License 2.0
182 stars 39 forks source link

Stop using vi.hoist for mocking stores #1884

Open axel7083 opened 1 month ago

axel7083 commented 1 month ago

Is your enhancement related to a problem? Please describe

As per exposed by @benoitf in https://github.com/containers/podman-desktop-extension-ai-lab/pull/1849#discussion_r1795172109 we can simplify the tests by using a better manner which do not need the problematic vi.hoist (poor typing).

Describe the solution you'd like

E.g.

vi.mock('../stores/modelsInfo', async () => ({
  modelsInfo: {
    subscribe: vi.fn(),
    unsubscribe: vi.fn(),
  },
  }));

beforeEach(() => {
  const infos: Writable<ModelInfo[]> = writable([]);
  vi.mocked(modelsInfo).subscribe.mockImplementation((run) => (infos.subscribe(run)));
});

Describe alternatives you've considered

No response

Additional context

No response