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