Skip to content

otaviosoares/seneca-stub

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

A utility for stubbing seneca.js patterns

Resources

License

Stars

Watchers

Forks

Packages

No packages published