bogus
bogus is a small utility for stubbing dependencies when testing RequireJS based projects
Link Seam
In Working Effectively with Legacy Code, Michael Feathers describes Seams. In the vernacular of that book, bogus
would be considered a Link Seam.
Getting bogus
You can install bogus into your project using either npm
or bower
$ npm install bogus --save-dev
or
$ bower install bogus --save-dev
Usage
// SteeringWheel; // Car; // load bogus;});
Promises
Both bogus.require
and bogus.reset
return promises. The beforeEach
and
afterEach
in the example above can be written as:
; ;
Stub multiple dependencies
If you're stubbing several dependencies, you can pass a map of them to stub
var firstFake = {};var secondFake = {}; bogus;
Development
You can run the tests with
$ npm test
or with
$ mocha
if you have mocha installed as a global
See also
- Injecting Stubs/Mocks into Tests with Require.js - the blog post that laid the groundwork for what became bogus
- 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