/factor-in

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

Primary LanguageJavaScriptMIT LicenseMIT

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