/iterateTest

Utility to iterate over a test with sets of input data

Primary LanguageJavaScriptBSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

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)); }
	}
);