factor-in

1.1.2 • Public • Published

factor-in

NPM version build status Test coverage js-standard-style

A factory of factory functions. Share and extend object data.

Install

$ npm install --save factor-in

Usage

import factorIn from 'factor-in'
 
// Create our base object data we expect all
// factory functions to inherit from.
const f = factorIn ({
  foo () {},
  bar () {}
})
 
var obj = f ({ baz: 'Baz', qux: 'Qux' })
//=> {foo: foo(), bar: bar(), baz: 'Baz', qux: 'Qux'}
test('Demo component', nest => {
  // fixture to be shared across nested tests
  const fixture = factorIn({
    setWord () {},
    setMode () {}
  })
 
  nest.test('...with basic fixture', t => {
    const el = <Hello actions={ fixture() } />
    //> { setWord: function setWord () {}, setMode: function setMode () {} }
    t.equal(actual, expected, 'should have common methods')
    t.end()
  })
 
  nest.test('...with extended fixture', t => {
    const extendedFixture = fixture({ setAction () {} })
    const el = <Hello actions={ extendedFixture } />
    //> { setWord: function setWord () {}, setMode: function setMode() {}, setAction: function setAction() {} }
    t.equal(actual, expected, 'should have common and extended methods')
    t.end()
  })
})

License

MIT © Chris Buttery

Package Sidebar

Install

npm i factor-in

Weekly Downloads

7

Version

1.1.2

License

MIT

Last publish

Collaborators

  • chrisbuttery