{"id":19382920,"url":"https://github.com/kenoxa/svelte-jsx","last_synced_at":"2025-04-23T20:32:33.959Z","repository":{"id":37960322,"uuid":"274401575","full_name":"kenoxa/svelte-jsx","owner":"kenoxa","description":"jsx for svelte  to simplify testing","archived":false,"fork":false,"pushed_at":"2022-12-05T15:12:18.000Z","size":927,"stargazers_count":38,"open_issues_count":17,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-02T20:11:29.194Z","etag":null,"topics":["js","jsx","svelte","testing"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kenoxa.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-06-23T12:36:31.000Z","updated_at":"2025-03-19T16:15:04.000Z","dependencies_parsed_at":"2023-01-24T05:46:10.833Z","dependency_job_id":null,"html_url":"https://github.com/kenoxa/svelte-jsx","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kenoxa%2Fsvelte-jsx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kenoxa%2Fsvelte-jsx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kenoxa%2Fsvelte-jsx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kenoxa%2Fsvelte-jsx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kenoxa","download_url":"https://codeload.github.com/kenoxa/svelte-jsx/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250509879,"owners_count":21442515,"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":["js","jsx","svelte","testing"],"created_at":"2024-11-10T09:23:51.638Z","updated_at":"2025-04-23T20:32:32.676Z","avatar_url":"https://github.com/kenoxa.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# svelte-jsx\n\n\u003e [jsx] for [Svelte](https://svelte.dev/) to simplify testing\n\n[![License](https://badgen.net/npm/license/svelte-jsx)](https://github.com/kenoxa/svelte-jsx/blob/main/LICENSE)\n[![Latest Release](https://badgen.net/npm/v/svelte-jsx)](https://www.npmjs.com/package/svelte-jsx)\n[![View changelog](https://badgen.net/badge/%E2%80%8B/Explore%20Changelog/green?icon=awesome)](https://changelogs.xyz/svelte-jsx)\n\n[![CI](https://github.com/kenoxa/svelte-jsx/workflows/CI/badge.svg)](https://github.com/kenoxa/svelte-jsx/actions?query=branch%3Amain+workflow%3ACI)\n[![Coverage Status](https://badgen.net/coveralls/c/github/kenoxa/svelte-jsx/main)](https://coveralls.io/github/kenoxa/svelte-jsx?branch=main)\n[![PRs Welcome](https://badgen.net/badge/PRs/welcome/purple)](http://makeapullrequest.com)\n[![Conventional Commits](https://badgen.net/badge/Conventional%20Commits/1.0.0/cyan)](https://conventionalcommits.org)\n\n\u003e If your are not using [babel](https://babeljs.io/) take a look at [svelte-htm].\n\n## What?\n\nWrite Svelte components in [jsx].\n\n## Why?\n\nThis is especially useful for [testing Svelte components](https://github.com/svelte-society/recipes-mvp/blob/master/testing.md).\n\n## Installation\n\n```sh\nnpm install --save-dev svelte-jsx\n```\n\n### Babel Configuration\n\nThis package allows you to write Svelte using the [jsx] syntax (see\n[@babel/plugin-transform-react-jsx](https://babeljs.io/docs/en/babel-plugin-transform-react-jsx)).\nA [working babel setup](https://babeljs.io/setup) is therefore required.\n\nIn your [babel configuration file](https://babeljs.io/docs/en/configuration) add:\n\n```json\n{\n  \"plugins\": [\n    [\"@babel/plugin-transform-react-jsx\", { \"runtime\": \"automatic\", \"importSource\": \"svelte-jsx\" }]\n  ]\n}\n```\n\nor, if you already use [@babel/preset-react](https://babeljs.io/docs/en/babel-preset-react),\nmake sure `runtime` is set to `automatic`:\n\n```json\n{\n  \"presets\": [[\"@babel/preset-react\", { \"runtime\": \"automatic\", \"importSource\": \"svelte-jsx\" }]]\n}\n```\n\nIf you're unable to use `svelte-jsx` as a global `importSource` for your project,\nyou may use the [@jsxImportSource](https://babeljs.io/docs/en/babel-plugin-transform-react-jsx#customizing-the-automatic-runtime-import)\npragma within a file:\n\n```js\n/** @jsxImportSource svelte-jsx */\n\nrender(\n  \u003cSomeComponent\u003e\n    \u003cSomeChild /\u003e\n  \u003c/SomeComponent\u003e,\n)\n```\n\n## Usage\n\n\u003e Please note the differences to the Svelte component syntax [outlined below](#api).\n\n```js\nimport { render, fireEvent } from '@testing-library/svelte'\n\nimport Button from '../src/Button.svelte'\n\ntest('should render', async () =\u003e {\n  let clicked = 0\n  const { getByRole } = render(\u003cButton on_click={() =\u003e (clicked += 1)}\u003eClick Me!\u003c/Button\u003e)\n\n  const button = getByRole('button')\n\n  await fireEvent.click(button)\n\n  expect(clicked).toBe(1)\n})\n```\n\n## API\n\nCurrently, [jsx] does not allow the use of `:` in attribute/property names. As a\nworkaround, every `:` can be replaced with `_` (for example `bind_value` is converted\nto `bind:value` for Svelte).\n\nFor Svelte compatibility we convert `className` to `class`.\n\nWe [aim to support](https://github.com/kenoxa/svelte-hyperscript#feature-set) all\nSvelte features. In some cases this is not possible. For those cases we provided feasible\nworkarounds. See [svelte-hyperscript] for further details.\n\nSome notable differences include:\n\n- Using [stores](https://svelte.dev/docs#svelte_store) to allow reactivity\n\n  ```js\n  import { render } from '@testing-library/svelte'\n  import userEvent from '@testing-library/user-event'\n  import { writable, get } from 'svelte/store'\n\n  test('write into an input', async () =\u003e {\n    const text = writable()\n    const { getByRole } = render(\u003cinput bind_value={text}\u003e)\n\n    const input = getByRole('textbox')\n\n    await userEvent.type(input, 'some text')\n\n    expect(get(text)).toBe('some text')\n  })\n  ```\n\n- Action properties lack the possibility to pass parameters to the action\n\n  ```js\n  import action from 'some-action-module'\n\n  const Div = \u003cdiv use_action={(node) =\u003e action(node, parameters)}\u003e\u003c/div\u003e\n  ```\n\n## Related Projects\n\n- [svelte-htm] - [**H**yperscript **T**agged **M**arkup](https://www.npmjs.com/package/htm)\n  for Svelte; a jsx-like [syntax](https://www.npmjs.com/package/htm#syntax-like-jsx-but-also-lit)\n  using [Tagged Templates]\n- [svelte-hyperscript] - the core of this implementation\n- [svelte-fragment-component] - a utility component\n- [@testing-library/svelte](https://testing-library.com/docs/svelte-testing-library/intro) -\n  helps to test UI components in a user-centric way\n- [reactjs/rfcs/0000-create-element-changes](https://github.com/reactjs/rfcs/blob/createlement-rfc/text/0000-create-element-changes.md)\n\n## Support\n\nThis project is free and open-source, so if you think this project can help you or\nanyone else, you may [star it on GitHub](https://github.com/kenoxa/svelte-jsx). Feel\nfree to [open an issue](https://github.com/kenoxa/svelte-jsx/issues) if you have any\nideas, questions, or if you've found a bug.\n\n## Contribute\n\nThanks for being willing to contribute!\n\n**Working on your first Pull Request?** You can learn how from this _free_ series\n[How to Contribute to an Open Source Project on GitHub](https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github)\n\nWe are following the [Conventional Commits](https://www.conventionalcommits.org) convention.\n\n### Develop\n\n- `npm test`: Run test suite\n- `npm run build`: Generate bundles\n- `npm run lint`: Lints code\n\n## NPM Statistics\n\n[![NPM](https://nodei.co/npm/svelte-jsx.png)](https://nodei.co/npm/svelte-jsx/)\n\n## License\n\n`svelte-jsx` is open source software [licensed as MIT](https://github.com/kenoxa/svelte-jsx/blob/main/LICENSE).\n\n[tagged templates]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#Tagged_templates\n[all modern browsers]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#Browser_compatibility\n[jsx]: https://reactjs.org/docs/introducing-jsx.html\n[svelte-htm]: https://www.npmjs.com/package/svelte-htm\n[svelte-hyperscript]: https://www.npmjs.com/package/svelte-hyperscript\n[svelte-fragment-component]: https://www.npmjs.com/package/svelte-fragment-component\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkenoxa%2Fsvelte-jsx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkenoxa%2Fsvelte-jsx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkenoxa%2Fsvelte-jsx/lists"}