Menu
Libraries |
Category

dainte

  • Purpose: Dainte is a testing library designed for Svelte components, inspired by Enzyme. It provides tools for testing both runtime and server-side rendering (SSR) simultaneously with minimal configuration.

  • Key Features:

    • Test Svelte runtime and SSR together
    • Zero-config compatibility with Jest
    • Low-level compile options to ensure tests match production behavior
    • Component state introspection
  • Target Audience: Developers working with Svelte who need a streamlined way to test components in both DOM and SSR environments.

  • Core Functions:

    • dainte.compile: Compiles Svelte components from source files with customizable options like dev, immutable, and hydratable. Supports Svelte's compile options fa-solid fa-up-right-from-square.
    • dainte.mount: Mounts a component in a JSDom environment, allowing DOM interactions and state updates. Includes aliases for easy access to the component instance and DOM elements.
    • dainte.render: Renders components to HTML for SSR testing, with options like preserveWhitespace and preserveComments.
    • instance.inspect: Provides a snapshot of top-level variables and imports when compiled with inspect: true, useful for debugging state.
  • Framework Support: Primarily focused on Svelte, with deep integration for both DOM and SSR testing.

  • Example Use Case:

    import { mount } from 'dainte';
    const { app, document } = await mount('./App.svelte');
    app.$set({ answer: 42 });
    expect(document.querySelector('#answer').textContent).toBe('42');
    

sveltetesting

Comments