stub-everything
v0.0.1
Published
Stub or mock complex objects and classes. Uses SinonJS
Downloads
9
Readme
Stub-Everything
Never worry about Javascript and Typescript stubbing again. Stubs complex objects and classes all at once. Uses SinonJS for stub objects
Install
npm install --save-dev stub-everything
API
stubEverything(thingToMock: object|array|T): object|array|T
restoreEverything(thingToRestore: object|array|T): object|array|T
stubEverything
The default export. Will take an object/class/array and recursively stub every function in the prototype if a class, or the object properties if object literal.
restoreEverything
Named export. Use to restore the stubs.
Example
import stubEverything, { restoreEverything } from 'stub-everything';
import * as complexObject from './complexObject';
import functionUsesComplexObject from './functionUsesComplexObject';
beforeEach(() => {
stubEverything(complexObject);
});
afterEach(() => {
restoreEverything(complexObject);
});
it('should fire method on complexObject', function() {
functionUsesComplexObject(complexObject);
expect(complexObject.someMethod.called).toEqual(true); //should be true
});