{"id":15552228,"url":"https://github.com/bahmutov/cy-spok","last_synced_at":"2025-06-16T21:40:22.981Z","repository":{"id":37094645,"uuid":"227852136","full_name":"bahmutov/cy-spok","owner":"bahmutov","description":"Playing with spok inside Cypress","archived":false,"fork":false,"pushed_at":"2024-09-28T06:27:40.000Z","size":3378,"stargazers_count":43,"open_issues_count":6,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-03T14:13:05.431Z","etag":null,"topics":["assertion","cypress","cypress-plugin"],"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":"2019-12-13T13:59:58.000Z","updated_at":"2024-09-28T06:27:14.000Z","dependencies_parsed_at":"2023-12-30T08:23:01.109Z","dependency_job_id":"6e9bb604-42e6-4f45-aeb4-0ea88ca75f56","html_url":"https://github.com/bahmutov/cy-spok","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Fcy-spok","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Fcy-spok/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Fcy-spok/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Fcy-spok/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bahmutov","download_url":"https://codeload.github.com/bahmutov/cy-spok/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234553597,"owners_count":18851473,"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":["assertion","cypress","cypress-plugin"],"created_at":"2024-10-02T14:13:00.253Z","updated_at":"2025-06-16T21:40:22.971Z","avatar_url":"https://github.com/bahmutov.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cy-spok [![renovate-app badge][renovate-badge]][renovate-app] ![cypress version](https://img.shields.io/badge/cypress-14.4.1-brightgreen)\n\n\u003e Playing with [spok](https://github.com/thlorenz/spok) inside Cypress test\n\n\u003c!-- prettier-ignore-start --\u003e\nCI | status\n--- | ---\n[lint](.github/workflows/lint.yml) | ![Lint status](https://github.com/bahmutov/cy-spok/workflows/lint/badge.svg?branch=master)\n[badges](.github/workflows/badges.yml) | ![Badges status](https://github.com/bahmutov/cy-spok/workflows/badges/badge.svg?branch=master)\n[cy-spok](.github/workflows/main.yml) | ![GH Action status](https://github.com/bahmutov/cy-spok/workflows/main/badge.svg?branch=master)\n[cy-spok-example](https://github.com/bahmutov/cy-spok-example) | ![cy-spok-example status](https://github.com/bahmutov/cy-spok-example/workflows/tests/badge.svg?branch=master)\n\u003c!-- prettier-ignore-end --\u003e\n\n## Learn\n\n- 📺 Watch [Introduction To cy-spok Plugin For Writing Powerful Assertions For Objects](https://www.youtube.com/watch?v=MLDsqBd_gVU)\n- 📺 Watch [Confirm Text In Multiple Page Elements Using cy-spok](https://youtu.be/l6_OXPiqkxQ)\n- 📺 Watch [Verify Cypress Component Prop Calls Using Stubs, cypress-map, and cy-spok](https://youtu.be/zdjjBRt6Z74)\n- 📺 Watch [Refactor Cypress API Tests Part 1: Use cy-spok Plugin](https://youtu.be/zGO3LNx-agk)\n- 📝 Read [Asserting Network Calls from Cypress Tests](https://www.cypress.io/blog/2019/12/23/asserting-network-calls-from-cypress-tests/)\n- 📝 Read [Change E2E Tests From UI To API To App Actions](https://glebbahmutov.com/blog/ui-to-api-to-app-actions/)\n- 📝 Read [Two Simple Tricks To Make Your Cypress Tests Better](https://glebbahmutov.com/blog/two-cypress-tricks/)\n- 📝 Read [Crawl Weather Using Cypress](https://glebbahmutov.com/blog/crawl-weather/)\n- 📝 Read [Testing React Number Format Component Example](https://glebbahmutov.com/blog/test-react-number-format/)\n- 📝 Read [Cypress Flakiness Examples](https://glebbahmutov.com/blog/flakiness-example/)\n- 📝 Read [Use Cypress For API Testing](https://glebbahmutov.com/blog/use-cypress-for-api-testing/)\n- 📝 Read [Check Fees And Totals Using Cypress](https://glebbahmutov.com/blog/check-fees-using-cypress/)\n- 📝 Read [Retry Network Requests](https://glebbahmutov.com/blog/retry-network-requests/)\n- 🎓 Covered in my course [Cypress Plugins](https://cypress.tips/courses/cypress-plugins)\n  - [Lesson e1: Validate network requests using cy-spok](https://cypress.tips/courses/cypress-plugins/lessons/e1)\n  - [Lesson e2: Use your own predicates to validate object properties](https://cypress.tips/courses/cypress-plugins/lessons/e2)\n  - [Lesson e3: Validate URL search parameters](https://cypress.tips/courses/cypress-plugins/lessons/e3)\n  - [Lesson e4: Check and control the Redux store using cy-spok plugin](https://cypress.tips/courses/cypress-plugins/lessons/e4)\n- 🎓 Covered in my course [Cypress Network Testing Exercises](https://cypress.tips/courses/network-testing)\n  - [Bonus 28: Use cy-spok plugin to write complex assertions](https://cypress.tips/courses/network-testing/lessons/bonus28)\n  - [Bonus 101: Confirm the server supports caching using the ETag header](https://cypress.tips/courses/network-testing/lessons/bonus101)\n- 🎓 Covered in my course [Cypress vs Playwright](https://cypress.tips/courses/cypress-vs-playwright)\n  - [Lesson d8: Assert complex objects](https://cypress.tips/courses/cypress-vs-playwright/lessons/d8)\n\n## Install\n\n```\n$ npm i -D cy-spok\n```\n\n## Use\n\nSee [spok](https://github.com/thlorenz/spok#readme) docs\n\n```js\n// in your Cypress spec file\nimport spok from 'cy-spok'\n\nconst object = {\n  one: 1,\n  two: 2,\n  three: 3,\n  four: 4,\n  helloWorld: 'hello world',\n  anyNum: 999,\n  anotherNum: 888,\n  anArray: [1, 2],\n  anotherArray: [1, 2, 3],\n  anObject: {},\n  id: 'abc123',\n  list: ['one', 'two', 'three'],\n}\n\n// using Spok\n// https://github.com/thlorenz/spok#readme\ncy.wrap(object, { timeout: 2000 }).should(\n  spok({\n    $topic: 'spok-example', // optional\n    one: spok.ge(1),\n    two: 2,\n    three: spok.range(2, 6),\n    four: spok.lt(5),\n    helloWorld: spok.startsWith('hello'),\n    anyNum: spok.type('number'),\n    anotherNum: spok.number,\n    anArray: spok.array,\n    anObject: spok.ne(undefined),\n    // test a string using regular expression\n    id: spok.test(/^abc\\d{3}$/),\n    // array with 3 elements\n    list: spok.arrayElements(3),\n  }),\n)\n```\n\nSee [cypress/integration/spec.js](cypress/integration/spec.js) here and in the [cy-spok-example](https://github.com/bahmutov/cy-spok-example) repo.\n\n![Spok in action](img/cy-spok.gif)\n\n## vs deep.equal\n\nSpok prints a lot more information when using it compared to `deep.equal`. Note that Spok is a subset, not strict value equality.\n\n![deep.equal vs spok for complex objects](./img/vs-deep-equal.png)\n\nSee [deep-equal-spec.js](./cypress/integration/deep-equal-spec.js)\n\n## Treat arrays as an object\n\n```js\n// verify each item in an array as an object\ncy.wrap(['one', 42, 'three']).should(\n  spok({\n    0: spok.string,\n    1: spok.number,\n    2: spok.string,\n  }),\n)\n```\n\n## Use Lodash predicates\n\nLodash has many predicate functions `is...`, see [Lodash docs](https://lodash.com/docs)\n\n```js\ncy.wrap({\n  name: 'Joe',\n  age: 20,\n}).should(\n  spok({\n    name: Cypress._.isString,\n    age: Cypress._.isNumber,\n  }),\n)\n```\n\n## Own predicate\n\nAny synchronous function that returns a boolean could be a predicate\n\n```js\n// it is a list of strings\nconst areGreetings = (list) =\u003e\n  Array.isArray(list) \u0026\u0026 list.every(Cypress._.isString)\n\ncy.wrap({\n  greetings: ['hello', 'hi'],\n}).should(\n  spok({\n    greetings: areGreetings,\n  }),\n)\n```\n\n## First failure only\n\nIf there are multiple failing predicates, only the first one is shown. All passing predicates are shown\n\n```js\ncy.wrap({\n  name: 'Joe',\n  age: 42,\n  job: 'chimney sweeper',\n  location: 'Boston',\n  present: true,\n}).should(\n  spok({\n    name: 'Mary', // fails\n    age: 42, // passes\n    job: 'secret agent', // fails\n    location: 'Boston', // passes\n    present: spok.type('boolean'), // passes\n  }),\n)\n```\n\n![Only the first failed predicate is shown](./img/two.png)\n\n## Small print\n\nAuthor: Gleb Bahmutov \u0026lt;gleb.bahmutov@gmail.com\u0026gt; \u0026copy; 2021\n\n- [@bahmutov](https://twitter.com/bahmutov)\n- [glebbahmutov.com](https://glebbahmutov.com)\n- [blog](https://glebbahmutov.com/blog)\n- [videos](https://www.youtube.com/glebbahmutov)\n- [presentations](https://slides.com/bahmutov)\n- [cypress.tips](https://cypress.tips)\n- [Cypress Advent 2021](https://cypresstips.substack.com/)\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/cy-spok/issues) on Github\n\n## MIT License\n\nCopyright (c) 2021 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[renovate-badge]: https://img.shields.io/badge/renovate-app-blue.svg\n[renovate-app]: https://renovateapp.com/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbahmutov%2Fcy-spok","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbahmutov%2Fcy-spok","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbahmutov%2Fcy-spok/lists"}