sar

sinon-auto-restore

Place stubs and spies which are removed automatically after tests

Showing:

Popularity

Downloads/wk

1

GitHub Stars

1

Maintenance

Last Commit

3yrs ago

Contributors

3

Package

Dependencies

1

Size (min+gzip)

4.6KB

License

MIT

Type Definitions

Tree-Shakeable

Yes?

Categories

Readme

sinon-auto-restore

npm codecov.io JavaScript Style Guide npm David Greenkeeper badge semantic-release

A library that provides a streamlined interface for creating lots of sinon stubs and spies on objects that can be automatically restored with a simple call to restore that can be placed in your global teardown function. Beyond that, it also allows you to replace fields in the same way.

API

onObject(objectName)

Provides an interface to stub and spy on methods of an object and to replace fields.

  • .stub()
    Replaces all own methods of an object by stubs.
  • .stub(n)
    Replaces all own and inherited methods of an object by stubs going up to n levels up the prototype chain.
  • .stub('method1' <,'method2' <...>>)
    Replaces only the given methods by stubs.
  • .stub('method', replacementFunction)
    Replaces a given method by a stub with the provided functionality.
  • .spy()
    Spies on all own methods of an object.
  • .spy(n)
    Spies on all own and inherited methods of an object going up to n levels up the prototype chain.
  • .spy('method1' <,'method2' <...>>)
    Spies on the given methods of an object.
  • .replace('field', replacementValue)
    Replaces a given field by another value.

All of the above methods can be chained. In case different method calls would modify the same field or method, only the last method call is used, i.e.,

onObject(myObject).spy().stub('stubbedMethod')

spies on all own methods of myObject except .stubbedMethod, which is replaced by a stub. This also works across different calls to onObject, i.e.

onObject(myObject).spy()
onObject(myObject).stub('stubbedMethod')

would have exactly the same effect.

restore()

Restores all stubs, spies and replacements.

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100