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