{"id":13615397,"url":"https://github.com/symfony/stimulus-testing","last_synced_at":"2025-10-19T17:30:25.785Z","repository":{"id":45539951,"uuid":"317179015","full_name":"symfony/stimulus-testing","owner":"symfony","description":"Testing-library integration for Symfony UX","archived":false,"fork":false,"pushed_at":"2023-10-03T16:03:52.000Z","size":17,"stargazers_count":25,"open_issues_count":0,"forks_count":3,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-01-29T22:23:14.932Z","etag":null,"topics":["javascript","symfony"],"latest_commit_sha":null,"homepage":"https://symfony.com/ux","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/symfony.png","metadata":{"funding":{"github":"fabpot","tidelift":"packagist/symfony/symfony","custom":"https://symfony.com/sponsor"},"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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-11-30T09:52:52.000Z","updated_at":"2024-12-08T14:07:20.000Z","dependencies_parsed_at":"2024-01-17T00:40:30.996Z","dependency_job_id":"2d62604f-4f96-484d-8cb4-3b7209aa934c","html_url":"https://github.com/symfony/stimulus-testing","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/symfony%2Fstimulus-testing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/symfony%2Fstimulus-testing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/symfony%2Fstimulus-testing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/symfony%2Fstimulus-testing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/symfony","download_url":"https://codeload.github.com/symfony/stimulus-testing/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237172279,"owners_count":19266643,"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":["javascript","symfony"],"created_at":"2024-08-01T20:01:13.058Z","updated_at":"2025-10-19T17:30:25.779Z","avatar_url":"https://github.com/symfony.png","language":"JavaScript","funding_links":["https://github.com/sponsors/fabpot","https://tidelift.com/funding/github/packagist/symfony/symfony","https://symfony.com/sponsor"],"categories":["JavaScript"],"sub_categories":[],"readme":"# Symfony UX Stimulus testing\n\n\u003e [!WARNING]\n\u003e **Deprecated**: This package is deprecated and will not receive any further updates.\n\nBecause this package only provides very small helpers to help write tests for Stimulus controllers, and is tightly coupled with [Jest](https://jestjs.io/), [jsdom](https://github.com/jsdom/jsdom) and [Testing Library](https://testing-library.com/) dependencies, we can no longer recommend it.\n\nIn 2025, we cannot force developers to install Jest (and [~270 sub-dependencies](https://npmgraph.js.org/?q=jest) including [Babel](https://babeljs.io/)) and the like, since [many test runners exist](https://npmtrends.com/ava-vs-japa-vs-jasmine-vs-jest-vs-karma-vs-mocha-vs-tap-vs-vitest), and many of them are more modern and much faster, like [Vitest](https://vitest.dev/).\n\nWe want to give you the choice to use the best tools for your needs, and not force you to use what we suggested in the past.\n\nTo migrate from `@symfony/stimulus-testing`, you can follow these steps:\n\n1. Install the dev dependencies `@testing-library/jest-dom @testing-library/dom`;\n    you may also want to install `mutationobserver-shim regenerator-runtime` if you still have \n    legacy code or _architecture_.\n2. In the file `assets/test/setup.js`, replace imports:\n```diff\n-import '@symfony/stimulus-testing/setup';\n+import '@testing-library/jest-dom';\n```\n3. Create the file `assets/test/stimulus-helpers.js` with the following content:\n```js\nexport function mountDOM(html = '') {\n    const div = document.createElement('div');\n    div.innerHTML = html;\n    document.body.appendChild(div);\n\n    return div;\n}\n\nexport function clearDOM() {\n    document.body.innerHTML = '';\n}\n```\n4. In your tests files, replace imports for `mountDOM` and `clearDOM`:\n```diff\n// assets/test/controllers/hello_controller.test.js\n-import { clearDOM, mountDOM } from '@symfony/stimulus-testing';\n+import { clearDOM, mountDOM } from '../stimulus-helpers';\n```\n5. And finally, remove the `@symfony/stimulus-testing` dependency from your project.\n\n---\n\nSymfony UX Stimulus testing is a low-level package to help write tests for Stimulus controllers\nin applications and reusable packages.\n\nSymfony UX Stimulus testing is currently considered **experimental**.\n\n## Installation\n\n```sh\nyarn add @symfony/stimulus-testing\n```\n\n## Usage\n\nSymfony UX Stimulus testing ships several tools to help write tests for Stimulus controllers:\n\n* it uses [Jest](https://jestjs.io/) as test runner ;\n* it relies internally on [jsdom](https://github.com/jsdom/jsdom) and mutationobserver-shim to emulate a DOM\n  implementation and allow to execute Stimulus controllers in the console ; \n* it provides an integration of [Testing Library](https://testing-library.com/) ;\n* it provides helper functions to ease Stimulus tests development in Symfony projects and bundles ;\n\nTo start using Symfony UX Testing, you first need to configure a testing environment:\n\n1. Create a `assets/test` directory ;\n\n2. Create a `assets/test/setup.js` file to initialize Symfony UX Testing:   \n\n```js\nimport '@symfony/stimulus-testing/setup';\n```\n\n3. Create a `assets/jest.config.js` file for Jest configuration:\n \n```js\nmodule.exports = {\n    'testRegex': 'test/.*\\\\.test.js',\n    'setupFilesAfterEnv': ['./test/setup.js']\n};\n```\n\n4. Create a `assets/.babelrc` file for Babel configuration (you may need to install Babel, \n`@babel/plugin-proposal-class-properties` and `@babel/preset-env` if you haven't already):\n\n```json\n{\n    \"presets\": [\"@babel/preset-env\"],\n    \"plugins\": [\"@babel/plugin-proposal-class-properties\"]\n}\n```\n\n5. Finally, create your first test, for instance `hello_controller.test.js`:\n\n```js\nimport { Application } from '@hotwired/stimulus';\nimport { clearDOM, mountDOM } from '@symfony/stimulus-testing';\nimport HelloController from '../controllers/hello_controller.js';\n\nconst startStimulus = () =\u003e {\n    const application = Application.start();\n    application.register('hello', HelloController);\n};\n\ndescribe('HelloController', () =\u003e {\n    let container;\n\n    beforeEach(() =\u003e {\n        container = mountDOM('\u003cdiv data-controller=\"hello\"\u003e\u003c/div\u003e');\n    });\n\n    afterEach(() =\u003e {\n        clearDOM();\n    });\n\n    it('connect', async () =\u003e {\n        startStimulus();\n\n        // Write a test here ...\n    });\n\n    // You can create other tests here\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsymfony%2Fstimulus-testing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsymfony%2Fstimulus-testing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsymfony%2Fstimulus-testing/lists"}