spiderworm / iterateTest

Utility to iterate over a test with sets of input data

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

iterateTest.js -- David Millet

Useful for iterating over test code with more than one set of inputs.

Ex:

var tests = iterateTest(
	{
		lowNumbers: { a: 1, b: 10 },
		highNumbers: { a: 20, b: 5 },
		sameNumbers: function() { var vals = { a: 44 }; vals.b = vals.a; return vals; }
	},
	function testMultiply(v) {
		if (multiply(v.a, v.b) !== v.a * v.b) {
			throw new Error('nope');
		}
	}
);

tests();

With BDD:

describe('multiply', iterateTest(
	{
		lowNumbers: { a: 1, b: 10 },
		highNumbers: { a: 20, b: 5 },
		sameNumbers: function() { var vals = { a: 44 }; vals.b = vals.a; return vals; }
	},
	function(vals, setName) {
		it('multiplies ' vals.a + ' and ' + vals.b + ' together', function () {
			expect(multiply(vals.a, vals.b)).to.equal(vals.a * vals.b);
		}
	}
);

Configure output:

iterateTest.config(
	{
		echo: function(values, setName) { console.log('iterating with values', setName, JSON.stringify(values)); }
	}
);

About

Utility to iterate over a test with sets of input data

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:JavaScript 100.0%