From 092ea182dce06741bada91c9c015170ccdb74ba8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Sun, 21 Jul 2013 16:11:09 -0700 Subject: [PATCH] Improve tests for moveAbove() / moveBelow(). --- test/lib/helpers.js | 12 ++++++++---- test/tests/Item_Order.js | 16 ++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/test/lib/helpers.js b/test/lib/helpers.js index bbd9d566..adea76a2 100644 --- a/test/lib/helpers.js +++ b/test/lib/helpers.js @@ -27,14 +27,18 @@ QUnit.jsDump.setParser('object', function (obj, stack) { : objectParser).call(this, obj, stack); }); +function getFunctionBody(func) { + return func.toString().match( + /^\s*function[^\{]*\{([\s\S]*)\}\s*$/)[1] + .replace(/ /g, '') + .replace(/^\s+|\s+$/g, ''); +} + // Override equals to convert functions to message and execute them as tests() function equals(actual, expected, message, tolerance) { if (typeof actual === 'function') { if (!message) { - message = actual.toString().match( - /^\s*function[^\{]*\{([\s\S]*)\}\s*$/)[1] - .replace(/ /g, '') - .replace(/^\s+|\s+$/g, ''); + message = getFunctionBody(actual); if (/^return /.test(message)) { message = message .replace(/^return /, '') diff --git a/test/tests/Item_Order.js b/test/tests/Item_Order.js index 9fdec965..be268f20 100644 --- a/test/tests/Item_Order.js +++ b/test/tests/Item_Order.js @@ -56,22 +56,18 @@ test('Item Order', function() { test('Item#moveAbove(item) / Item#moveBelow(item)', function() { var item0, item1, item2; - var testMove = function(command, indexes) { + + function testMove(command, indexes) { paper.project.clear(); new Layer(); item0 = new Group(); item1 = new Group(); item2 = new Group(); command(); - equals(function() { - return item0.index; - }, indexes[0], command.toString()); - equals(function() { - return item1.index; - }, indexes[1]); - equals(function() { - return item2.index; - }, indexes[2]); + var str = getFunctionBody(command); + equals(item0.index, indexes[0], str + ': item0.index'); + equals(item1.index, indexes[1], str + ': item1.index'); + equals(item2.index, indexes[2], str + ': item2.index'); } testMove(function() { item0.moveBelow(item0) }, [0,1,2]);