1.0.0 • Published 11 months ago

@treedom/tap-data-provider v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

tap-data-provider

Extends node-tap with a new tests assertion and introduces the concept of "DataProvider" in tests.

Install

npm install @treedom/tap-data-provider

Usage

The module will add a new tests method which accept the following params:

  • name: The name of test, same of the original tap test function
  • dataSource: The data with which the tests will be executed.
  • fn: A function similar to the original one, but which receives also a variable number of params based on data source elements

Datasource

Datasource can be provided in form of array or data provider function. In case of function it must return an array.

The data source array element can be of type array or object.

In case of array element, the first value will be the input params of the callback function, and the second value will be the expected

In case of object element it should have the propery input and expected that will be mapped in the relative params of the callback function

const tap = require('tap')
const tdp = require('@treedom/tap-data-provider')
tdp(tap)

function sum(number1, number2) {
  return number1 + number2
}

// Data source given as array
const datasource = [
  { input: {value_1: 1, value_2: 2}, expected: 3},
  { input: {value_1: 3, value_2: 2}, expected: 5},
]
tap.tests('sum should return right values', datasource, (tap, {value_1, value_2}, expected) => {
  tap.equal(sum(value_1, value_2), expected)
  tap.end()
})

// Data source given as provider function
function sumDataProvider() {
  return [
    [{value_1: 1, value_2: 2}, 3],
    [{value_1: 3, value_2: 2}, 5],
  ]
}
tap.tests('sum should return right values', sumDataProvider, (tap, {value_1, value_2}, expected) => {
  tap.equal(sum(value_1, value_2), expected)
  tap.end()
})
1.0.0

11 months ago

0.1.0-beta.0

11 months ago

1.0.0-beta.0

11 months ago

0.0.2-beta.1

11 months ago

0.0.2-beta.0

11 months ago

0.0.1-beta.0

11 months ago