seneca-stub

1.2.2 • Public • Published

seneca-stub

A utility for stubbing seneca.js patterns using Sinon.JS

This is based on Denis Luchkin-Zhou's stub utility from seneca-as-promised

Install

npm install seneca-stub

Getting Started

const Seneca = require('seneca')();
require('seneca-stub')(Seneca);

Return static data

const stub = Seneca.stub('role:test,cmd:stub', { foo: 'bar' });
await Seneca.act('role:test,cmd:stub', { herp: 'derp' }); // { foo: 'bar' }
 
stub.data(); // { role: 'test', cmd: 'stub', herp: 'derp' }

Use custom function

const stub = Seneca.stub('role:test,cmd:stub', function(args, done) {
    var result = {greeting: 'hello '+ args.name }
    done(null, result)
});
await Seneca.act('role:test,cmd:stub', { name: 'john' }); // { greeting: 'hello john' }
 
stub.data(); // { role: 'test', cmd: 'stub', name: 'john' }

If value provided to Seneca.stub is an Error, then it will be thrown instead of being returned.

Readme

Keywords

Package Sidebar

Install

npm i seneca-stub

Weekly Downloads

2

Version

1.2.2

License

MIT

Last publish

Collaborators

  • otaviosoares