{"id":16255168,"url":"https://github.com/mroderick/bogus","last_synced_at":"2025-03-19T21:30:35.649Z","repository":{"id":16020075,"uuid":"18763688","full_name":"mroderick/bogus","owner":"mroderick","description":"bogus is a small utility for mocking dependencies when testing RequireJS based projects","archived":false,"fork":false,"pushed_at":"2018-06-05T11:03:03.000Z","size":31,"stargazers_count":5,"open_issues_count":0,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-02-28T23:21:15.605Z","etag":null,"topics":["javascript","link-seam","requirejs","seam","stub"],"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/mroderick.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}},"created_at":"2014-04-14T14:30:16.000Z","updated_at":"2023-08-23T22:12:01.000Z","dependencies_parsed_at":"2022-07-13T13:10:31.944Z","dependency_job_id":null,"html_url":"https://github.com/mroderick/bogus","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mroderick%2Fbogus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mroderick%2Fbogus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mroderick%2Fbogus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mroderick%2Fbogus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mroderick","download_url":"https://codeload.github.com/mroderick/bogus/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244056406,"owners_count":20390719,"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":["javascript","link-seam","requirejs","seam","stub"],"created_at":"2024-10-10T15:28:37.072Z","updated_at":"2025-03-19T21:30:35.372Z","avatar_url":"https://github.com/mroderick.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bogus [![Build Status](https://travis-ci.org/mroderick/bogus.svg)](https://travis-ci.org/mroderick/bogus) [![Dependency Status](https://david-dm.org/mroderick/bogus.svg)](https://david-dm.org/mroderick/bogus) [![Dependency status](https://david-dm.org/mroderick/bogus/dev-status.svg)](https://david-dm.org/mroderick/bogus#info=devDependencies\u0026view=table)\n\nbogus is a small utility for stubbing dependencies when testing [RequireJS](http://requirejs.org) based projects\n\n#### Link Seam\n\nIn [Working Effectively with Legacy Code](http://www.informit.com/store/working-effectively-with-legacy-code-9780131177055), Michael Feathers describes *[Seams](http://www.informit.com/articles/article.aspx?p=359417)*. In the vernacular of that book, `bogus` would be considered a *Link Seam*.\n\nGetting bogus\n----------------------\n\nYou can install bogus into your project using either `npm` or `bower`\n\n\n```bash\n$ npm install bogus --save-dev\n```\nor\n\n```bash\n$ bower install bogus --save-dev\n```\n\n## Usage\n\n```javascript\n\n// SteeringWheel\ndefine('SteeringWheel', function(){\n    function SteeringWheel(){\n        this.color = 'black';\n    }\n\n    return SteeringWheel;\n});\n\n// Car\ndefine('Car', ['SteeringWheel'], function(SteeringWheel){\n    function Car(){\n        this.steeringWheel = new SteeringWheel();\n    }\n\n    Car.prototype.getSteeringWheelColor = function getSteeringWheelColor(){\n        return this.steeringWheel.color;\n    };\n\n    return Car;\n});\n\n// load bogus\ndefine([\n    'bower_components/bogus/bogus'  // this is ofc. dependent on where you installed it\n], function(\n    bogus\n){\n    describe('myModule', function{\n        var Car;\n\n        beforeEach(function(done){\n            var fakeSteeringWheel = function(){\n                this.color = 'blue';\n            };\n\n            // stub out a dependency (SteeringWheel) with our fake\n            bogus.stub('SteeringWheel', fakeSteeringWheel);\n\n            // load Car module, that depends on SteeringWheel\n            bogus.require('Car', function(module){\n                Car = module;\n                done();\n            });\n        });\n\n        afterEach(function(done){\n            bogus.reset(done);\n        });\n\n        describe('Car', function(){\n            describe('getSteeringWheelColor method', function(){\n                it('should return the actual color of the SteeringWheel', function(){\n                    var car = new Car();\n\n                    assert.equal(car.getSteeringWheelColor(), 'blue');\n                });\n            });\n        });\n    });\n});\n```\n\n### Promises\n\nBoth `bogus.require` and `bogus.reset` return promises. The `beforeEach` and\n`afterEach` in the example above can be written as:\n\n```javascript\nbeforeEach(function(){\n    var fakeSteeringWheel = function(){\n        this.color = 'blue';\n    };\n\n    bogus.stub('SteeringWheel', fakeSteeringWheel);\n\n    return bogus.require('Car').then(function(module){\n        Car = module;\n    });\n});\n\nafterEach(function(){\n    return bogus.reset();\n});\n```\n\n### Stub multiple dependencies\n\nIf you're stubbing several dependencies, you can pass a map of them to `stub`\n\n```javascript\nvar firstFake = {};\nvar secondFake = {};\n\nbogus.stub({\n    'path/to/first/dependency': firstFake,\n    'path/to/second/dependency': secondFake\n});\n```\n\n## Development\n\nYou can run the tests with\n\n```bash\n$ npm test\n```\n\nor with\n\n```bash\n$ mocha\n```\n\nif you have [mocha](http://mochajs.org/) installed as a global\n\n## See also\n\n* [Injecting Stubs/Mocks into Tests with Require.js](http://www.symphonious.net/2013/07/08/injecting-stubsmocks-into-tests-with-require-js/) - the blog post that laid the groundwork for what became bogus\n* [Squire.js](https://github.com/iammerrick/Squire.js/) - also stubs out RequireJS dependencies. I couldn't get it to stop [re-downloading all the dependencies for each test ... nor could someone else](https://github.com/iammerrick/Squire.js/issues/39)\n\n## License\n\nMIT: \u003chttp://mrgnrdrck.mit-license.org\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmroderick%2Fbogus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmroderick%2Fbogus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmroderick%2Fbogus/lists"}