@svizzle/dev/test

Methods

(static) makePrinter() → {object}

Source:
Since:
  • 0.1.0

Return a console.log interceptor

Example
describe('tapAppendTo', function () {
	let printer;
	before(function () {
		printer = makePrinter();
		printer.init();
	});
	beforeEach(function () {
		printer.reset();
	});
	after(function () {
		printer.restore();
	});

	it('should print the provided array and element and return the result of appending the element to the array', function () {
		const actual1 = tapAppendTo([1, 2, 3], 4);
		const expected1 = [1, 2, 3, 4];
		const actual2 = tapAppendTo([1, 2], 'a');
		const expected2 = [1, 2, 'a'];

		// 2 taps -> invoked console.logs 2 times
		const expectedLog = [
			[[1, 2, 3], 4],
			[[1, 2], 'a']
		];

		assert.deepStrictEqual(actual1, expected1);
		assert.deepStrictEqual(actual2, expected2);
		assert.deepStrictEqual(printer.getLog(), expectedLog);

		printer.print('I can still log stuff') // console.log is preserved
	});
});
describe('console.log still works in other tests', function () {
	it('console.logs', function () {
		assert.deepStrictEqual(true, true);
		console.log('foo') // 'foo'
	});
});
Returns:
Type
object