{"id":19755416,"url":"https://github.com/nathancahill/dainte","last_synced_at":"2025-08-01T07:15:39.440Z","repository":{"id":42928115,"uuid":"241580526","full_name":"nathancahill/dainte","owner":"nathancahill","description":"Painless testing for Svelte components","archived":false,"fork":false,"pushed_at":"2023-01-05T16:24:59.000Z","size":1670,"stargazers_count":102,"open_issues_count":9,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-30T07:17:03.374Z","etag":null,"topics":["svelte","testing"],"latest_commit_sha":null,"homepage":"https://nathancahill.com/dainte/introducing","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nathancahill.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-02-19T09:23:29.000Z","updated_at":"2024-09-28T22:26:30.000Z","dependencies_parsed_at":"2023-02-04T06:50:13.391Z","dependency_job_id":null,"html_url":"https://github.com/nathancahill/dainte","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathancahill%2Fdainte","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathancahill%2Fdainte/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathancahill%2Fdainte/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathancahill%2Fdainte/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nathancahill","download_url":"https://codeload.github.com/nathancahill/dainte/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224208083,"owners_count":17273674,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["svelte","testing"],"created_at":"2024-11-12T03:11:06.746Z","updated_at":"2024-11-12T03:11:07.408Z","avatar_url":"https://github.com/nathancahill.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Dainte ![CI](https://github.com/nathancahill/dainte/workflows/CI/badge.svg)\n\nPainless testing for Svelte components, inspired by Enzyme.\n\n🥂 \u0026nbsp;Test Svelte runtime and SSR simultanously\u003cbr/\u003e\n🎭 \u0026nbsp;Zero-config compatible with Jest\u003cbr/\u003e\n🤖 \u0026nbsp;Low-level compile options to ensure that tests match prod\u003cbr/\u003e\n🔎 \u0026nbsp;Component \"state\" introspection\u003cbr/\u003e\n\n## Usage\n\n### `dainte.compile`\n\n```js\nresult: {\n    // Compiled Svelte component class\n    Component,\n\n    // Alias to component as specified or inferred name\n    [name],\n} = await dainte.compile(source: string, options?: {...})\n```\n\nCreates a compiled Svelte component class from a source file path.\n\nThe following options can be passed to `compile`, including [svelte.compile options](https://svelte.dev/docs#svelte_compile).\nThe `dev` option defaults to `true` for testing. None are required:\n\n| option       | default                 | description                                                      |\n|:-------------|:------------------------|:-----------------------------------------------------------------|\n| `name`       | `'Component'`           | Name of the component class, inferred from filename              |\n| `dev`        | `true`                  | Perform runtime checks and provide debugging information         |\n| `immutable`  | `false`                 | You promise not to mutate any objects                            |\n| `hydratable` | `false`                 | Enables the hydrate: true runtime option                         |\n| `legacy`     | `false`                 | Generates code that will work in IE9 and IE10                    |\n| `accessors`  | `false`                 | Getters and setters will be created for the component's props    |\n| `css`        | `true`                  | Include CSS styles in JS class                                   |\n| `generate`   | `'dom'`                 | Create JS DOM class or object with `.render()`                   |\n| `inspect`    | `false`                 | Include `instance.inspect()` accessor                            |\n| `plugins`    | `[svelte(), resolve()]` | Advanced option to manually specify Rollup plugins for bundling. |\n\n#### Example\n\n```js\nimport { compile } from 'dainte'\n\nconst { App } = await compile('./App.svelte')\n\nconst app = new App({\n    target: document.body,\n})\n```\n\n### `dainte.mount`\n\n```js\nresult: {\n    // Svelte component instance\n    instance,\n\n    // Compiled JS component class\n    Component,\n\n    // JSDom window and document where component is mounted.\n    window,\n    document,\n\n    // Alias to the Component with specified or inferred name\n    [name],\n\n    // Alias to the instance with lowercase specified or inferred name\n    [lowercase(name)],\n}  = await mount(source: string, options?: {...})\n```\n\nCreates an instance of a component from a source file path. Mounts the instance\nin a JSDom.\n\nAll `compile` options can also be passed to `mount`. Additionally, these options, including the [component initialisation options](https://svelte.dev/docs#Creating_a_component), can be provided:\n\n| option       | default                 | description                                                      |\n|:-------------|:------------------------|:-----------------------------------------------------------------|\n| `html`       | `'\u003cbody\u003e\u003c/body\u003e'`       | HTML to initiate the JSDom instance with                         |\n| `target`     | `'body'`                | Render target (as a query selector, *not a DOM element* as in Svelte initialisation) |\n| `anchor`     | `null`                  | Render anchor (as a query selector, *not a DOM element* as in Svelte initialisation) |\n| `props`      | `{}`                    | An object of properties to supply to the component               |\n| `hydrate`    | `false`                 | Upgrade existing DOM instead of replacing it                     |\n| `intro`      | `false`                 | Play transitions on initial render                               |\n\nA `svelte.tick` is awaited between mounting the instance and resolving the `mount` promise so\nthat the DOM is full initialized. An additional `svelte.tick` should be awaited\nbetween updating the component and reading from the DOM.\n\n#### Example\n\n```js\nimport { mount } from 'dainte'\nimport { tick } from 'svelte'\n\nconst { app, document } = await mount('./App.svelte')\napp.$set({ answer: 42 })\nawait tick()\n\nexpect(document.querySelector('#answer').textContent).toBe('42')\n```\n\n### `dainte.render`\n\n```js\nresult: {\n    head,\n    html,\n    css,\n} = await dainte.render(source: string, options?: {...})\n```\n\nWraps Svelte's server-side `Component.render` API for rendering a component\nto HTML.\n\nThe following options can be passed to `render`, including [svelte.compile options](https://svelte.dev/docs#svelte_compile).\nThe `dev` option defaults to `true` for testing. None are required:\n\n| option       | default                 | description                                                      |\n|:-------------|:------------------------|:-----------------------------------------------------------------|\n| `dev`        | `true`                  | Perform runtime checks and provide debugging information         |\n| `immutable`  | `false`                 | You promise not to mutate any objects                            |\n| `hydratable` | `false`                 | Enables the hydrate: true runtime option                         |\n| `css`        | `true`                  | Include CSS styles in JS class                                   |\n| `preserveComments` | `false`           | HTML comments will be preserved                                  |\n| `preserveWhitespace` | `false`         | Keep whitespace inside and between elements as you typed it      |\n| `plugins`    | `[svelte(), resolve()]` | Advanced option to manually specify Rollup plugins for bundling. |\n\n#### Example\n\n```js\nimport { render } from 'dainte'\n\nconst { html } = await render('./App.svelte')\n// '\u003cdiv id=\"answer\"\u003e42\u003c/div\u003e'\n```\n\n### `instance.inspect`\n\n```js\nvariables: {\n    // Snapshot of all top-level variables and imports\n} = instance.inspect()\n```\n\nCompiling with `inspect: true` adds a `inspect()` function to the component instance.\nCalling the function returns a snapshot object of all top-level variables and their\ncurrent values. Snapshot values are not reactive and `inspect()` must be called\nagain to retrieve updated values.\n\n#### Example\n\n```js\nimport { mount } from 'dainte'\n\nconst { app } = await mount('./App.svelte', { inspect: true })\nconst { answer } = app.inspect()\n// 42\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnathancahill%2Fdainte","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnathancahill%2Fdainte","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnathancahill%2Fdainte/lists"}