{"id":16594722,"url":"https://github.com/levrik/sinon-spy-react","last_synced_at":"2025-08-23T18:14:26.519Z","repository":{"id":57361809,"uuid":"49777123","full_name":"levrik/sinon-spy-react","owner":"levrik","description":"Spy on React.js classes with Sinon","archived":false,"fork":false,"pushed_at":"2016-12-28T17:06:38.000Z","size":24,"stargazers_count":8,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-14T21:23:07.857Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/levrik.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2016-01-16T14:42:34.000Z","updated_at":"2019-07-11T17:40:09.000Z","dependencies_parsed_at":"2022-09-26T16:41:02.859Z","dependency_job_id":null,"html_url":"https://github.com/levrik/sinon-spy-react","commit_stats":null,"previous_names":["dernivel/sinon-spy-react"],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/levrik/sinon-spy-react","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/levrik%2Fsinon-spy-react","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/levrik%2Fsinon-spy-react/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/levrik%2Fsinon-spy-react/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/levrik%2Fsinon-spy-react/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/levrik","download_url":"https://codeload.github.com/levrik/sinon-spy-react/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/levrik%2Fsinon-spy-react/sbom","scorecard":{"id":113142,"data":{"date":"2025-08-04","repo":{"name":"github.com/levrik/sinon-spy-react","commit":"f8c494d8dbe1d9520fedaa3fe976cee05834d523"},"scorecard":{"version":"v5.2.1-28-gc1d103a9","commit":"c1d103a9bb9f635ec7260bf9aa0699466fa4be0e"},"score":3.2,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#packaging"}},{"name":"Code-Review","score":1,"reason":"Found 2/12 approved changesets -- score normalized to 1","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#code-review"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#pinned-dependencies"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#maintained"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#binary-artifacts"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#token-permissions"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#cii-best-practices"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#vulnerabilities"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 21 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-15T16:27:54.034Z","repository_id":57361809,"created_at":"2025-08-15T16:27:54.034Z","updated_at":"2025-08-15T16:27:54.034Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271760532,"owners_count":24816441,"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","status":"online","status_checked_at":"2025-08-23T02:00:09.327Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-10-11T23:47:15.424Z","updated_at":"2025-08-23T18:14:26.475Z","avatar_url":"https://github.com/levrik.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"sinon-spy-react [![npm package](https://img.shields.io/npm/v/sinon-spy-react.svg?style=flat-square)](https://www.npmjs.com/package/sinon-spy-react)\n==============\nSpy on React.js classes with Sinon\n\n## DEPRECATED\n\nPlease use classes instead of the `React.createClass` API since it's deprecated. Spying and stubbing of class methods is possible without this library.\n\n#### How do I migrate my tests after conversion to classes?\n\n```javascript\n// Before\nconst spy = spyOnComponentMethod(Component, 'componentDidMount');\n\n// After\nconst spy = sinon.spy(Component.prototype, 'componentDidMount');\n```\n\n```javascript\n// Before\nconst stub = stubComponentMethod(Component, 'getInitialState').returns({\n  foo: 'bar'\n});\n\n// After\nconst stub = sinon.stub(Component.prototype, 'getInitialState').returns({\n  foo: 'bar'\n});\n```\n\n## Installation\n\n```\nnpm install sinon-spy-react --save-dev\n```\n\n\u003e For the old 1.x documentation, look [here](https://github.com/levrik/sinon-spy-react/blob/1.1.2/README.md).\n\n## API\n\n### `spyOnComponentMethod(reactClass, methodName)`\n\nThis method creates and returns a spy on the given React component class and method. The original function is wrapped into the spy. That means the original code will still be executed. To prevent this or execute custom code use a stub.\n\n**Note**: It isn't possible to create a spy on a method which does not exist except for lifecycle methods (e.g. `componentDidMount`). `getDefaultProps` and `getChildContext` are not supported. For `getInitialState` use a stub. That can be used to return a custom initial state for the test scenario, for example.\n\n### `stubComponentMethod(reactClass, methodName)`\n\nThis method stubs the method on the given React component class and returns the stub.\n\n**Note**: The `restore` method of the stub only restores the function on the React class definition, not on the instance. Create a new instance of the component after calling `restore` to get an instance with the restored method.\n\n## Examples\n\n```javascript\nimport assert from 'assert'; // obviously you can use a assertion library of your choice\nimport React from 'react';\nimport TestUtils from 'react-addons-test-utils';\nimport { spyOnComponentMethod, stubComponentMethod } from 'sinon-spy-react';\n\nimport Component from './Component'; // some React component to test\n\nit('calls componentDidMount after mounting', () =\u003e {\n    const spy = spyOnComponentMethod(Component, 'componentDidMount');\n    const component = TestUtils.renderIntoDocument(\u003cComponent /\u003e);\n\n    assert(spy.calledOnce);\n});\n\nit('does something with specific initial state', () =\u003e {\n    const stub = stubComponentMethod(Component, 'getInitialState').returns({\n      foo: 'bar' // the stubbed/mocked initial state\n    });\n    const spy = spyOnComponentMethod(Component, 'someSpecialMethod'); // gets called if state.foo === 'bar'\n    const component = TestUtils.renderIntoDocument(\u003cComponent /\u003e);\n\n    assert(spy.calledOnce);\n\n    stub.restore();\n});\n```\n\nThe examples are written in ES6 but you can use this library without problems with ES5.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flevrik%2Fsinon-spy-react","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flevrik%2Fsinon-spy-react","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flevrik%2Fsinon-spy-react/lists"}