0.0.2 • Published 7 years ago

iterate-test v0.0.2

Weekly downloads
1
License
BSD-3-Clause
Repository
github
Last release
7 years ago

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

7 years ago

0.0.1

7 years ago