{"id":22473112,"url":"https://github.com/bas080/spyn","last_synced_at":"2025-03-27T16:26:09.957Z","repository":{"id":31552136,"uuid":"123523421","full_name":"bas080/spyn","owner":"bas080","description":"Javascript spy helpers","archived":false,"fork":false,"pushed_at":"2022-04-03T08:46:20.000Z","size":65,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-18T14:07:24.082Z","etag":null,"topics":["minimal","spy","testing"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/spyn","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/bas080.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2018-03-02T03:09:01.000Z","updated_at":"2022-04-17T02:39:44.000Z","dependencies_parsed_at":"2022-08-07T16:30:31.808Z","dependency_job_id":null,"html_url":"https://github.com/bas080/spyn","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bas080%2Fspyn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bas080%2Fspyn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bas080%2Fspyn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bas080%2Fspyn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bas080","download_url":"https://codeload.github.com/bas080/spyn/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245880958,"owners_count":20687642,"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":["minimal","spy","testing"],"created_at":"2024-12-06T12:19:00.772Z","updated_at":"2025-03-27T16:26:09.935Z","avatar_url":"https://github.com/bas080.png","language":"JavaScript","readme":"# Spyn\n[![Build Status](https://travis-ci.org/bas080/spyn.svg?branch=master)](https://travis-ci.org/bas080/spyn)\n\nSafe and minimal spying tool for testing purposes.\n\n# Installation\n\n`npm install spyn --save-dev`\n\n# Reference\n\n## Spy\n\n\u003e Takes a function and returns a function that is being spied on.\n\n```javascript\nconst spiedFn = spy(sum)\n\nspiedFn(1, 2) // =\u003e 3\n```\n\nThere is also a optional configuration object which allows you to define what\nfunction call properties are stored in the calls array. By default it stores\narguments and return values.\n\n```js\nconst spiedFn = spy(sum, {arguments: false, this: true})\n\nspiedFn.call('thiz', 'a', 'b') // =\u003e 'ab'\n\ncalls(spiedFn) // =\u003e [{this: 'thiz', return: 'ab'}]\n```\n\n## Calls\n\n\u003e Takes a spy function and returns an array containing information of each call\n\n```javascript\nconst spiedFn = spy(multiply)\n\nspiedFn(1,2)\n\ncalls(spiedFn) // =\u003e [{arguments: [1,2], return: 2}]\n```\n\n## Original\n\n\u003e Returns the original function of the spy.\n\n```javascript\nconst spiedFn = spy(divide)\n\nspiedFn === divide // =\u003e false\n\noriginal(spiedFn) === divide // =\u003e true\n```\n\n# Usage\n\nSpies tend to be used only in tests. They allow you to observe and automate the\nchecking of function calls.\n\nIt is good practice to remove a spy when the test has completed. This prevents\nedge cases.\n\n# Tests\n\n```javascript\nnpm install \u0026\u0026 npm test\n```\n\n# Example\n\n- [form-data-extended](https://github.com/bas080/form-data-extended/blob/master/lib/form-data.spec.js#L27)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbas080%2Fspyn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbas080%2Fspyn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbas080%2Fspyn/lists"}