{"id":15937650,"url":"https://github.com/ficusjs/ficusjs-testing","last_synced_at":"2025-08-16T12:31:31.062Z","repository":{"id":60703433,"uuid":"359749323","full_name":"ficusjs/ficusjs-testing","owner":"ficusjs","description":"Helper functions for web component testing","archived":false,"fork":false,"pushed_at":"2023-09-09T06:28:00.000Z","size":420,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":5,"default_branch":"main","last_synced_at":"2024-11-08T12:51:11.800Z","etag":null,"topics":["ficusjs","frontend","testing","web-components"],"latest_commit_sha":null,"homepage":"https://docs.ficusjs.org","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/ficusjs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"ficusjs"}},"created_at":"2021-04-20T08:57:27.000Z","updated_at":"2024-04-16T13:32:09.000Z","dependencies_parsed_at":"2024-10-29T13:03:41.157Z","dependency_job_id":null,"html_url":"https://github.com/ficusjs/ficusjs-testing","commit_stats":{"total_commits":19,"total_committers":1,"mean_commits":19.0,"dds":0.0,"last_synced_commit":"342e265e590d7645d6244e1f86cc3f595a6c9f77"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ficusjs%2Fficusjs-testing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ficusjs%2Fficusjs-testing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ficusjs%2Fficusjs-testing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ficusjs%2Fficusjs-testing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ficusjs","download_url":"https://codeload.github.com/ficusjs/ficusjs-testing/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230037388,"owners_count":18163127,"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":["ficusjs","frontend","testing","web-components"],"created_at":"2024-10-07T05:04:25.780Z","updated_at":"2024-12-16T22:46:30.201Z","avatar_url":"https://github.com/ficusjs.png","language":"JavaScript","funding_links":["https://github.com/sponsors/ficusjs"],"categories":[],"sub_categories":[],"readme":"# FicusJS testing\n\n\u003cimg src=\"img/ficus-icon-optimised.svg\" alt=\"FicusJS\" width=\"150\" align=\"right\"\u003e\n\nThe [FicusJS testing](https://www.npmjs.com/package/@ficusjs/testing) package provides lightweight helper functions for web component testing.\n\nThis package provides browser globals such as `window` and `document` using [jsdom](https://www.npmjs.com/package/jsdom) which is an implementation of many browser APIs ideal for testing but is not an actual browser.\n\nWe recommend using a tool such as [Cypress](https://www.cypress.io/) for browser end-to-end tests.\n\n## Running tests\n\nThis package contains functions intended for a NodeJS environment and not a real browser. It is therefore, best used for fast iteration.\n\nThe functions can be used with any NodeJS testing framework.\n\nThe following functions are available in the [FicusJS testing](https://www.npmjs.com/package/@ficusjs/testing) package.\n\n- `init` - a function for initializing the test environment\n- `render` - a function to render a web component for testing\n\n### init function\n\nThe `init` function initializes the NodeJS environment ready for testing.\n\nSimply call `init` in your set-up hook.\n\n```js\nimport test from 'ava'\nimport { init, render } from '@ficusjs/testing'\n\ntest.before(init)\n\n// if passing options to JSDOM\ntest.before(() =\u003e init({ runScripts: 'dangerously' }))\n```\n\nThe `init` function accepts the following optional arguments:\n\n| Name       | Type     | Description                           |\n|------------|----------|---------------------------------------|\n| `options`  | `object` | An object of options to pass to JSDOM |\n\n### render function\n\nThe `render` function will create a new web component instance for testing.\n\nIt returns a DOM instance of the component.\n\n```js\nimport test from 'ava'\nimport { init, render } from '@ficusjs/testing'\n\ntest.before(init)\n\ntest('render basic component', async t =\u003e {\n    const comp = await render('basic-comp', () =\u003e import('../src/component.mjs'), { foo: 'bar' })\n    t.is(comp.querySelector('p').textContent, 'Basic component with bar')\n})\n```\n\nThe `render` function accepts the following arguments:\n\n| Name       | Type       | Description                                                            |\n|------------|------------|------------------------------------------------------------------------|\n| `tagName`  | `string`   | The web component tag name                                             |\n| `importer` | `function` | A function that registers a web component. This can return a `Promise` |\n| `attrs`    | `object`   | An optional object of attributes to set on the component instance      |\n\n## Browser globals\n\nThe following browser globals are available when using the [FicusJS testing](https://www.npmjs.com/package/@ficusjs/testing) package.\n\n- `dom`\n- `Node`\n- `window`\n- `document`\n- `navigator`\n- `customElements`\n- `HTMLElement`\n\n## Testing components\n\nTesting web components can be done in a number of ways.\n\n- verifying that a component renders without throwing using a \"smoke test\"\n- shallow rendering and testing component output\n- full rendering and testing component lifecycle and state changes\n\nIt is a good idea to start with creating basic smoke tests for your components.\n\nTesting that a component mounts and ensures that it doesn't throw during rendering provides a lot of value with very little effort.\n\n## License\n\nThis project is licensed under the MIT License - see the [`LICENSE`](LICENSE) file for details.\n\n## Contributing to FicusJS\n\nAny kind of positive contribution is welcome! Please help us to grow by contributing to the project.\n\nIf you wish to contribute, you can work on any features you think would enhance the library. After adding your code, please send us a Pull Request.\n\n\u003e Please read [CONTRIBUTING](CONTRIBUTING.md) for details on our [CODE OF CONDUCT](CODE_OF_CONDUCT.md), and the process for submitting pull requests to us.\n\n## Support\n\nWe all need support and motivation. FicusJS is not an exception. Please give this project a ⭐️ to encourage and show that you liked it. Don't forget to leave a star ⭐️ before you move away.\n\nIf you found the library helpful, please consider [sponsoring us](https://github.com/sponsors/ficusjs).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fficusjs%2Fficusjs-testing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fficusjs%2Fficusjs-testing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fficusjs%2Fficusjs-testing/lists"}