data-client-vue-testing

Test Vue composables and components built on @data-client/vue with fixtures, nock, and fake timers.

2.0k|99|Updated Feb 15, 2019
One-click install
npx skills add https://github.com/reactive/data-client --skill data-client-vue-testing
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: data-client-vue-testing
Source: https://github.com/reactive/data-client/tree/main/.agents/skills/data-client-vue-testing
Command: npx skills add https://github.com/reactive/data-client --skill data-client-vue-testing

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Writing reliable tests for @data-client/vue composables and components requires handling Suspense resolution, reactive props, HTTP mocking, and time-based polling, which is error-prone without established patterns.

Core Features & Use Cases

  • Composable and Component Testing: Use renderDataCompose() and mountDataClient() with initialFixtures and resolverFixtures to test useSuspense, useQuery, useLive, and useSubscription without a real server.
  • HTTP Mocking and Polling Tests: Apply nock for real fetch round-trips and jest fake timers for deterministic polling and subscription tests.
  • Use Case: When a Vue 3 component using useSuspense with pollFrequency needs a regression test, mount it with mountDataClient, drive polls with jest.advanceTimersByTime, and assert reactive updates after mutating the mocked response.

Quick Start

Write a test for my Vue component that uses useSuspense with ArticleResource.get, mocking the response with fixtures.

Frequently Asked Questions about data-client-vue-testing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I test useSuspense composables in Vue 3?

Use renderDataCompose() with initialFixtures to pre-populate the store, then call waitForNextUpdate() to resolve the suspended state. useSuspense returns a Promise of a ComputedRef, so await it once and assert on the ref's .value.

How to mock HTTP requests when testing data-client Vue components?

Use nock with .persist() and an .options(/.*/).reply(200) preflight handler, since JSDOM fetch sends CORS preflights. For pure store behavior, prefer initialFixtures or resolverFixtures, which are lighter and need no global setup.

How do I test polling or useSubscription with jest fake timers?

Call jest.useFakeTimers() before rendering so the interval is created under fake timers, then use jest.advanceTimersByTime(frequency) to trigger polls. Await allSettled() and nextTick() before asserting, and restore real timers in afterEach.

Why does my Vue polling test hang with fake timers?

The flushUntil helper uses setTimeout, which never fires under fake timers, causing an infinite loop. Use a fake-timer-safe variant that only awaits Promise.resolve() and nextTick() without setTimeout.

Can I test reactive prop changes in data-client composables?

Yes, pass a reactive() object as props and wrap arguments in computed() so the composable tracks changes. Mutating props.id re-runs the query; setting args to null via computed makes the result undefined.