0.9.8 • Published 5 years ago

sinon-fluent v0.9.8

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

Sinon-Fluent

A package for stubbing fluent interfaces usings Sinon.js

Usage

Creating a basic stub interface

import stub from "sinon-fluent";
// const stub = require("sinon-fluent").default // using require

// Create stub
const structure = {
  foo: {
    bar: {
      baz: 999,
    },
  },
};
const fluentStub = stub(structure);

// Injection
testSubject.fluentDependency = fluentStub;

// Fluent method chaining
fluentStub
  .foo()
  .bar()
  .baz() // returns 999

Creating a stub replacing a key on an existing object

const existingObject = {
  foo: () => ({
    bar: () => ({
      baz: () => 0,
    }),
  }),
};

const fluentStub = stub({ bar: { baz: 99 } }, existingObject, 'foo');

existingObject
  .foo()
  .bar()
  .baz(); // returns 99

Assertion

You can use the with filter, to assert calls to stubs based on arguments in the function chain.

const fluentStub = stub({ foo: { bar: { baz: 'foo' } } });

fluentStub.foo(1, 2).bar(3, 4).baz(5, 6); // 'foo'

fluentStub.foo.with(1, 2).bar.with(3, 4).baz.with(5, 6).called;  // true
fluentStub.foo.with(1, 99).bar.with(3, 4).baz.with(5, 6).called; // false
fluentStub.foo.with(1, 2).bar.with(3, 4).baz.with(5, 99).called; // false
0.9.8

5 years ago

0.9.7

6 years ago

0.9.6

6 years ago

0.9.5

6 years ago

0.9.4

6 years ago

0.9.3

6 years ago

0.9.2

6 years ago

0.9.1

6 years ago

0.9.0

6 years ago