0.0.7 • Published 7 years ago

table-driven v0.0.7

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

table-driven

A small and simple table driven module for NodeJS

Requirement

  • NodeJS >= v7.6

Install

npm install table-driven

Basic usage

const tabledriven = require('table-driven')

const add = function (a, b) {
  return a + b
}

const result = tabledriven([
  [ 1, 2 ],
  [ 3, 4 ],
  [ 5, 6 ],
], add)

console.log(result) // [ 3, 7, 11 ]

Use as async

If give third argument as true then return a promise object and pass to then or catch as method chain.

const tabledriven = require('table-driven')

const pow = function (a) {
  return a ** a
}

tabledriven([ 1, 2, 3 ], add, true).then((result) => {
    console.log(result) // [ 1, 4, 27 ]
})      

with Mocha

Also use in the testing framework. Example is;

const assert = require('assert')
const tabledriven = require('table-driven')

describe('Test tabledriven as sync', () => {
  describe('Each one argument', () => {
    const markup = function (a) {
      return '<' + a + '>'
    }
    it('should return markuped string', () => {
      const arr = tabledriven(
          [
            1, 
            2
          ]
          , markup)
      assert.deepEqual(arr, [ '<1>', '<2>' ])
    })
  })

  describe('Each two arguments', () => {
    const add = function (a, b) {
      return a + b
    }
    it('should return result of addition of args', () => {
      const arr = tabledriven(
          [ 
            [ 1, 2 ], 
            [ 2, 2 ]
          ]
          , add)
      assert.deepEqual(arr, [ 3, 4 ])
    })
  })
}) 

Author

ktrysmt

License

MIT

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago