Skip to content
Discussion options

You must be logged in to vote

We are mocking all of our stores, too. We use the same pattern for every store.

We would mock a boolean $isAnonymous store this way:

File: mock-store.ts

import { writable } from 'svelte/store';

const mockIsAnonymousWritable = writable<boolean>();

export const mockIsAnonymousStore = {
  subscribe: mockIsAnonymousWritable.subscribe,
  set: vi.fn(), // add as much store functions you need here and set them to vi.fn(), so you can call expect() functions on them
  mockSetSubscribeValue: (value: boolean): void => mockIsAnonymousWritable.set(value)
};

In the test now you can just mock the real store with the mockStore. With mockIsAnonymousStore.mockSetSubscribeValue(...) you can set the value …

Replies: 2 comments 6 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by unikitty37
Comment options

You must be logged in to vote
6 replies
@unikitty37
Comment options

@vekunz
Comment options

@eliasdefaria
Comment options

@vekunz
Comment options

@eliasdefaria
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants