From 6db715ab87b40097463ac71f5d0d47a7e7abc1a0 Mon Sep 17 00:00:00 2001 From: rolux Date: Tue, 12 Jun 2012 15:31:46 +0200 Subject: [PATCH] don't modify test.statement; delete test.data when done --- source/Ox/js/JavaScript.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/source/Ox/js/JavaScript.js b/source/Ox/js/JavaScript.js index a37ae6d3..4bf17452 100644 --- a/source/Ox/js/JavaScript.js +++ b/source/Ox/js/JavaScript.js @@ -799,24 +799,26 @@ Ox.test = function(argument, callback) { item.tests && item.tests.some(function(test) { return test.expected; }) && item.tests.forEach(function(test) { - var actual, isAsync = regexp.test(test.statement); + var actual, statement = test.statement, + isAsync = regexp.test(statement); if (isAsync) { // Add a pending test Ox.test.data[id].tests[test.statement] = { + expected: test.expected, name: item.name, section: item.section }; // Patch the test statement - test.statement = test.statement.replace( + statement = statement.replace( regexp, - "$1'" + test.statement.replace(/'/g, "\\'") + "', " + "$1'" + statement.replace(/'/g, "\\'") + "', " ); } - if (test.expected || test.statement.match(/Ox\.test\./)) { + if (test.expected || statement.match(/Ox\.test\./)) { // Eval the statement, unless it's a script tag that doesn't // add a property to Ox.test - Ox.Log('TEST', test.statement); - actual = eval(test.statement); + Ox.Log('TEST', statement); + actual = eval(statement); } if (!isAsync && test.expected) { Ox.test.data[id].results.push({ @@ -824,7 +826,7 @@ Ox.test = function(argument, callback) { expected: test.expected, name: item.name, section: item.section, - statement: test.statement, + statement: statement, passed: Ox.isEqual( actual, eval('(' + test.expected + ')') ) @@ -835,6 +837,7 @@ Ox.test = function(argument, callback) { Ox.test.data[id].done = true; if (Ox.isEmpty(Ox.test.data[id].tests)) { callback(Ox.test.data[id].results); + delete Ox.test.data[id]; } } if (arguments.length == 2) { @@ -865,13 +868,13 @@ Ox.test = function(argument, callback) { }); Ox.test.data[id].results.push(Ox.extend(test, { actual: result, - expected: expected, statement: statement, passed: Ox.isEqual(result, expected) })); delete Ox.test.data[id].tests[statement]; if (Ox.test.data[id].done && Ox.isEmpty(Ox.test.data[id].tests)) { Ox.test.data[id].callback(Ox.test.data[id].results); + delete Ox.test.data[id]; } } };