Skip to content

Latest commit

 

History

History
41 lines (29 loc) · 1.02 KB

README.md

File metadata and controls

41 lines (29 loc) · 1.02 KB

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.