All Projects → nathancahill → Dainte

nathancahill / Dainte

Painless testing for Svelte components

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Dainte

Interference2020
Interference2020 Website
Stars: ✭ 46 (-39.47%)
Mutual labels:  svelte
Svelte Spa
.NET 5.0 Svelte v3 Rollup Bootstrap App
Stars: ✭ 59 (-22.37%)
Mutual labels:  svelte
Perfect Dark Mode
🌚🌝 Perfect Dark Mode
Stars: ✭ 70 (-7.89%)
Mutual labels:  svelte
Svelte Typescript Parcel
Svelte + Typescript + Parcel
Stars: ✭ 48 (-36.84%)
Mutual labels:  svelte
Svelte Starter
A Svelte starter template for projects.
Stars: ✭ 57 (-25%)
Mutual labels:  svelte
Elderjs
Elder.js is an opinionated static site generator and web framework for Svelte built with SEO in mind.
Stars: ✭ 1,102 (+1350%)
Mutual labels:  svelte
Svelte Pick A Place
Javascript location picker built with Svelte
Stars: ✭ 44 (-42.11%)
Mutual labels:  svelte
Shopathome
Choose from Angular, React, Svelte, and Vue applications with an Azure Functions API, that deploys to Azure Static Web Apps
Stars: ✭ 73 (-3.95%)
Mutual labels:  svelte
Svelte Canvas
🎨 Reactive canvas rendering with Svelte.
Stars: ✭ 59 (-22.37%)
Mutual labels:  svelte
One Click Extensions Manager
a simple chrome extension to manage chrome extension
Stars: ✭ 61 (-19.74%)
Mutual labels:  svelte
Svelte Store Router
Store-based router for Svelte
Stars: ✭ 54 (-28.95%)
Mutual labels:  svelte
Svelte Input Mask
Input masking component for Svelte with simple API and rich customization
Stars: ✭ 56 (-26.32%)
Mutual labels:  svelte
Svelte Feather Icons
Stars: ✭ 60 (-21.05%)
Mutual labels:  svelte
Felt
customizable community tools that feel good 💚 work in progress
Stars: ✭ 48 (-36.84%)
Mutual labels:  svelte
Ui
Powerful, reliable & fully featured Svelte UI library
Stars: ✭ 71 (-6.58%)
Mutual labels:  svelte
Svelte Custom Elements
Turn Svelte components into web components
Stars: ✭ 45 (-40.79%)
Mutual labels:  svelte
Svelte Datatable
DataTable for Svelte with Materialize
Stars: ✭ 59 (-22.37%)
Mutual labels:  svelte
Pingcrm Svelte
🦊 Ping CRM Svelte - A demo app to illustrate how Inertia.js works with Laravel and Svelte (hosted on a heroku free dyno).
Stars: ✭ 74 (-2.63%)
Mutual labels:  svelte
Thunderdome Planning Poker
⚡ Thunderdome is an open source agile planning poker tool in the theme of Battling for points
Stars: ✭ 70 (-7.89%)
Mutual labels:  svelte
Svelte Jester
A Jest transformer for Svelte - compile your components before importing them into tests.
Stars: ✭ 59 (-22.37%)
Mutual labels:  svelte

Dainte CI

Painless testing for Svelte components, inspired by Enzyme.

🥂  Test Svelte runtime and SSR simultanously
🎭  Zero-config compatible with Jest
🤖  Low-level compile options to ensure that tests match prod
🔎  Component "state" introspection

Usage

dainte.compile

result: {
    // Compiled Svelte component class
    Component,

    // Alias to component as specified or inferred name
    [name],
} = await dainte.compile(source: string, options?: {...})

Creates a compiled Svelte component class from a source file path.

The following options can be passed to compile, including svelte.compile options. The dev option defaults to true for testing. None are required:

option default description
name 'Component' Name of the component class, inferred from filename
dev true Perform runtime checks and provide debugging information
immutable false You promise not to mutate any objects
hydratable false Enables the hydrate: true runtime option
legacy false Generates code that will work in IE9 and IE10
accessors false Getters and setters will be created for the component's props
css true Include CSS styles in JS class
generate 'dom' Create JS DOM class or object with .render()
inspect false Include instance.inspect() accessor
plugins [svelte(), resolve()] Advanced option to manually specify Rollup plugins for bundling.

Example

import { compile } from 'dainte'

const { App } = await compile('./App.svelte')

const app = new App({
    target: document.body,
})

dainte.mount

result: {
    // Svelte component instance
    instance,

    // Compiled JS component class
    Component,

    // JSDom window and document where component is mounted.
    window,
    document,

    // Alias to the Component with specified or inferred name
    [name],

    // Alias to the instance with lowercase specified or inferred name
    [lowercase(name)],
}  = await mount(source: string, options?: {...})

Creates an instance of a component from a source file path. Mounts the instance in a JSDom.

All compile options can also be passed to mount. Additionally, these options, including the component initialisation options, can be provided:

option default description
html '<body></body>' HTML to initiate the JSDom instance with
target 'body' Render target (as a query selector, not a DOM element as in Svelte initialisation)
anchor null Render anchor (as a query selector, not a DOM element as in Svelte initialisation)
props {} An object of properties to supply to the component
hydrate false Upgrade existing DOM instead of replacing it
intro false Play transitions on initial render

A svelte.tick is awaited between mounting the instance and resolving the mount promise so that the DOM is full initialized. An additional svelte.tick should be awaited between updating the component and reading from the DOM.

Example

import { mount } from 'dainte'
import { tick } from 'svelte'

const { app, document } = await mount('./App.svelte')
app.$set({ answer: 42 })
await tick()

expect(document.querySelector('#answer').textContent).toBe('42')

dainte.render

result: {
    head,
    html,
    css,
} = await dainte.render(source: string, options?: {...})

Wraps Svelte's server-side Component.render API for rendering a component to HTML.

The following options can be passed to render, including svelte.compile options. The dev option defaults to true for testing. None are required:

option default description
dev true Perform runtime checks and provide debugging information
immutable false You promise not to mutate any objects
hydratable false Enables the hydrate: true runtime option
css true Include CSS styles in JS class
preserveComments false HTML comments will be preserved
preserveWhitespace false Keep whitespace inside and between elements as you typed it
plugins [svelte(), resolve()] Advanced option to manually specify Rollup plugins for bundling.

Example

import { render } from 'dainte'

const { html } = await render('./App.svelte')
// '<div id="answer">42</div>'

instance.inspect

variables: {
    // Snapshot of all top-level variables and imports
} = instance.inspect()

Compiling with inspect: true adds a inspect() function to the component instance. Calling the function returns a snapshot object of all top-level variables and their current values. Snapshot values are not reactive and inspect() must be called again to retrieve updated values.

Example

import { mount } from 'dainte'

const { app } = await mount('./App.svelte', { inspect: true })
const { answer } = app.inspect()
// 42
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].