don't modify test.statement; delete test.data when done

This commit is contained in:
rolux 2012-06-12 15:31:46 +02:00
parent b9c74fe895
commit 6db715ab87

View file

@ -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];
}
}
};