Mirror: The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.
at main 1.2 kB view raw
1import { createClient } from '@urql/core'; 2import { vi, expect, it, describe } from 'vitest'; 3import { get } from 'svelte/store'; 4 5import { queryStore } from './queryStore'; 6 7describe('queryStore', () => { 8 const client = createClient({ 9 url: 'https://example.com', 10 exchanges: [], 11 }); 12 13 const variables = {}; 14 const context = {}; 15 const query = '{ test }'; 16 const store = queryStore({ client, query, variables, context }); 17 18 it('creates a svelte store', () => { 19 const subscriber = vi.fn(); 20 store.subscribe(subscriber); 21 expect(subscriber).toHaveBeenCalledTimes(1); 22 }); 23 24 it('fills the store with correct values', () => { 25 expect(get(store).operation.kind).toBe('query'); 26 expect(get(store).operation.context.url).toBe('https://example.com'); 27 expect(get(store).operation.variables).toBe(variables); 28 29 expect(get(store).operation.query.loc?.source.body).toMatchInlineSnapshot(` 30 "{ 31 test 32 }" 33 `); 34 }); 35 36 it('adds pause handles', () => { 37 expect(get(store.isPaused$)).toBe(false); 38 39 store.pause(); 40 expect(get(store.isPaused$)).toBe(true); 41 42 store.resume(); 43 expect(get(store.isPaused$)).toBe(false); 44 }); 45});