{"id":13711706,"url":"https://github.com/bahmutov/cypress-hyperapp-unit-test","last_synced_at":"2025-09-28T20:31:10.797Z","repository":{"id":27954245,"uuid":"115682352","full_name":"bahmutov/cypress-hyperapp-unit-test","owner":"bahmutov","description":"Unit test Hyperapp components using Cypress","archived":false,"fork":false,"pushed_at":"2024-09-27T19:16:58.000Z","size":297,"stargazers_count":26,"open_issues_count":15,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-03T14:15:52.793Z","etag":null,"topics":["cypress","cypress-io","hyperapp","testing"],"latest_commit_sha":null,"homepage":"","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/bahmutov.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-12-29T03:26:26.000Z","updated_at":"2021-08-02T05:49:10.000Z","dependencies_parsed_at":"2023-09-24T21:23:39.795Z","dependency_job_id":"6d899a31-593e-43a8-9b26-5526ebe7014f","html_url":"https://github.com/bahmutov/cypress-hyperapp-unit-test","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Fcypress-hyperapp-unit-test","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Fcypress-hyperapp-unit-test/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Fcypress-hyperapp-unit-test/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Fcypress-hyperapp-unit-test/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bahmutov","download_url":"https://codeload.github.com/bahmutov/cypress-hyperapp-unit-test/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234558807,"owners_count":18852283,"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":["cypress","cypress-io","hyperapp","testing"],"created_at":"2024-08-02T23:01:10.855Z","updated_at":"2025-09-28T20:31:10.391Z","avatar_url":"https://github.com/bahmutov.png","language":"JavaScript","funding_links":[],"categories":["Uncategorized","Testing V1"],"sub_categories":["Uncategorized"],"readme":"# cypress-hyperapp-unit-test\n\n\u003e Unit test [Hyperapp](https://hyperapp.js.org/) components using [Cypress](https://www.cypress.io/)\n\n[![NPM][npm-icon] ][npm-url]\n\n[![Build status][ci-image] ][ci-url]\n[![semantic-release][semantic-image] ][semantic-url]\n[![js-standard-style][standard-image]][standard-url]\n[![Cypress.io dashboard](https://img.shields.io/badge/cypress.io-tests-green.svg?style=flat-square)][cypress dashboard url]\n[![renovate-app badge][renovate-badge]][renovate-app]\n\n[renovate-badge]: https://img.shields.io/badge/renovate-app-blue.svg\n[renovate-app]: https://renovateapp.com/\n\n## TLDR\n\n* What is this? This package allows you to use [Cypress](https://www.cypress.io/) test runner to unit test your Hyperapp components with zero effort. The component runs in the real browser with full power of Cypress E2E test runner: [live GUI, powerful API, screen recording, historical DOM snapshots, CI support, cross-platform](https://www.cypress.io/features/).\n\n* The line between unit testing a component that renders into a DOM, makes HTTP requests, uses browser API and an end-to-end test for a complete web application is becoming very blurry in my opinion. Hope this little bridge between Hyperapp and Cypress test runner proves it. See examples below - some of them are testing individual components, some full apps. But the unit and end-to-end tests look and run _very much alike_.\n\n## Install\n\nRequires [Node](https://nodejs.org/en/) version 6 or above.\n\n```sh\nnpm install --save-dev cypress-hyperapp-unit-test\n```\n\nalso requires peer dependencies in your project\n\n```sh\nnpm install cypress hyperapp\n```\n\n## API\n\nYou can import this module from your own tests\n\n```js\nimport { mount } from 'cypress-hyperapp-unit-test'\n// import or code state, action and view\nbeforeEach(() =\u003e {\n  mount(state, actions, view)\n})\n// you get fresh mini-app running in each test\n```\n\n## Use\n\nIn your Cypress spec files (the example below is from file [cypress/integration/hello-world-spec.js](cypress/integration/hello-world-spec.js)) mount the application, just like you would \"normally\".\n\n```js\nimport { mount } from 'cypress-hyperapp-unit-test'\nimport { h } from 'hyperapp'\n// view function we are testing\nconst view = (state, actions) =\u003e h('div', { class: 'greeting' }, 'Hello, World')\ndescribe('Hello World', () =\u003e {\n  beforeEach(() =\u003e {\n    const state = {}\n    const actions = {}\n    // no state or actions for this simple example\n    mount(state, actions, view)\n  })\n  it('shows greeting', () =\u003e {\n    // use any Cypress command - we have\n    // real Hyperapp application for testing\n    cy.contains('.greeting', 'Hello, World')\n  })\n})\n```\n\nStart Cypress using `$(npm bin)/cypress open` and execute the spec. You have full end-to-end test run but with your component! Why waste time on unit testing inside synthetic DOM's blackbox if you could _see_ the result, _inspect_ the DOM, _investigate_ how it works using time-travelling debugger?\n\n![Hello World shows greeting](images/hello-world.png)\n\n## Examples\n\n* [simple view function without any actions](cypress/integration/hello-world-spec.js)\n* [components without and with actions](cypress/integration/hello-world-component-spec.js)\n* [single TodoItem component](cypress/integration/todo-item-spec.js)\n* [entire TodoList component](cypress/integration/todo-list-spec.js)\n* [server XHR stubbing](cypress/integration/server-todos-spec.js)\n* [TodoMVC application E2E test](cypress/integration/todo-app-e2e.js) for [apps/todo.html](apps/todo.html)\n\nUnit tests and E2E tests start looking very much alike. Compare [TodoList unit test](cypress/integration/todo-list-spec.js) and [TodoMVC end-to-end test](cypress/integration/todo-app-e2e.js).\n\n* Components and tests for Hyperapp using JSX are their own repository [bahmutov/hyperapp-counter-jsx-example](https://github.com/bahmutov/hyperapp-counter-jsx-example) to keep this repo simple.\n\n## Repo organization\n\n* [src/index.js](src/index.js) the main file implementing `mount`\n* [components](components) different Hyper components for testing\n* [actions](actions) pure actions functions used from components and tests\n* [apps](apps) one or more complete bundled applications (build them using `npm run build`)\n* [cypress/integration](cypress/integration) example spec files showing various test situations\n\nSee video of tests running on CI on the project's [Cypress Dashboard][cypress dashboard url]\n\n## API Extras\n\n* Mounted component's actions object is attached to the global `Cypress.main` variable. The name `main` was picked because that's what Hyperapp uses in its docs `const main = app(state, ...)`\n* The `mount` function adds an action `_getState` to the `actions` object, if there is not one already present. This allows you to get the current state of the component for inspection.\n\n```js\nCypress.main.setName('Joe')\nCypress.main\n  ._getState()\n  .its('name')\n  .should('equal', 'Joe')\nCypress.main.setAge(37)\nCypress.main._getState().should('deep.equal', {\n  name: 'Joe',\n  age: 37\n})\n```\n\nNote: the `Cypress.main` wraps returned Hyperapp actions with `cy.then` to queue the calls through the Cypress command queue. Thus the above code looks synchronous, but in reality there could be DOM updates, network calls, etc, and it still works.\n\n## Package scripts\n\n* `npm run build` bundles complete applications if you want to run tests against full applications\n* `npm run cy:open` starts Cypress GUI, which is great for TDD mode\n* `npm run cy:run` runs Cypress headlessly, testing all specs. Same command [runs on CI](.travis.yml) with additional `--record` argument to record the run and send to the [Cypress Dashboard][cypress dashboard url]\n\n## Similar adaptors\n\n* [cypress-vue-unit-test](https://github.com/bahmutov/cypress-vue-unit-test)\n* [cypress-react-unit-test](https://github.com/bahmutov/cypress-react-unit-test)\n* [cypress-cycle-unit-test](https://github.com/bahmutov/cypress-cycle-unit-test)\n* [cypress-svelte-unit-test](https://github.com/bahmutov/cypress-svelte-unit-test)\n* [cypress-angular-unit-test](https://github.com/bahmutov/cypress-angular-unit-test)\n* [cypress-hyperapp-unit-test](https://github.com/bahmutov/cypress-hyperapp-unit-test)\n* [cypress-angularjs-unit-test](https://github.com/bahmutov/cypress-angularjs-unit-test)\n\n### Small print\n\nAuthor: Gleb Bahmutov \u0026lt;gleb.bahmutov@gmail.com\u0026gt; \u0026copy; 2017\n\n* [@bahmutov](https://twitter.com/bahmutov)\n* [glebbahmutov.com](https://glebbahmutov.com)\n* [blog](https://glebbahmutov.com/blog)\n\nLicense: MIT - do anything with the code, but don't blame me if it does not work.\n\nSupport: if you find any problems with this module, email / tweet /\n[open issue](https://github.com/bahmutov/cypress-hyperapp-unit-test/issues) on Github\n\n## MIT License\n\nCopyright (c) 2017 Gleb Bahmutov \u0026lt;gleb.bahmutov@gmail.com\u0026gt;\n\nPermission is hereby granted, free of charge, to any person\nobtaining a copy of this software and associated documentation\nfiles (the \"Software\"), to deal in the Software without\nrestriction, including without limitation the rights to use,\ncopy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the\nSoftware is furnished to do so, subject to the following\nconditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES\nOF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\nNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\nHOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\nWHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\nFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\nOTHER DEALINGS IN THE SOFTWARE.\n\n[npm-icon]: https://nodei.co/npm/cypress-hyperapp-unit-test.svg?downloads=true\n[npm-url]: https://npmjs.org/package/cypress-hyperapp-unit-test\n[ci-image]: https://travis-ci.org/bahmutov/cypress-hyperapp-unit-test.svg?branch=master\n[ci-url]: https://travis-ci.org/bahmutov/cypress-hyperapp-unit-test\n[semantic-image]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg\n[semantic-url]: https://github.com/semantic-release/semantic-release\n[standard-image]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg\n[standard-url]: http://standardjs.com/\n[cypress dashboard url]: https://dashboard.cypress.io/#/projects/zsoa27\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbahmutov%2Fcypress-hyperapp-unit-test","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbahmutov%2Fcypress-hyperapp-unit-test","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbahmutov%2Fcypress-hyperapp-unit-test/lists"}