Add lodashBizarro tests for cloning typed arrays.

This commit is contained in:
John-David Dalton
2014-07-06 17:05:37 -07:00
parent 92e5ae29c9
commit d89d5befa0
2 changed files with 41 additions and 11 deletions

View File

@@ -105,6 +105,10 @@
setProperty(document, '_createDocumentFragment', document.createDocumentFragment); setProperty(document, '_createDocumentFragment', document.createDocumentFragment);
document.createDocumentFragment = function() {}; document.createDocumentFragment = function() {};
setProperty(window, '_Float64Array', window.Float64Array);
if (!_Float64Array) {
setProperty(window, 'Float64Array', window.Uint8Array);
}
setProperty(window, 'global', window); setProperty(window, 'global', window);
setProperty(window, 'WinRTError', Error); setProperty(window, 'WinRTError', Error);
} }
@@ -145,6 +149,9 @@
} else { } else {
delete String.prototype.contains; delete String.prototype.contains;
} }
if (!_Float64Array) {
setProperty(window, 'Float64Array', undefined);
}
setProperty(Function.prototype, 'toString', Function.prototype._toString); setProperty(Function.prototype, 'toString', Function.prototype._toString);
setProperty(Object.prototype, 'hasOwnProperty', Object.prototype._hasOwnProperty); setProperty(Object.prototype, 'hasOwnProperty', Object.prototype._hasOwnProperty);

View File

@@ -316,7 +316,9 @@
].join('\n'))); ].join('\n')));
} }
catch(e) { catch(e) {
return; if (typeof require != 'function') {
return;
}
} }
// load ES6 Set shim // load ES6 Set shim
require('./asset/set'); require('./asset/set');
@@ -338,14 +340,14 @@
}); });
// fake DOM // fake DOM
setProperty(global, 'window', {}); setProperty(root, 'window', {});
setProperty(global.window, 'document', {}); setProperty(root.window, 'document', {});
setProperty(global.window.document, 'createDocumentFragment', function() { setProperty(root.window.document, 'createDocumentFragment', function() {
return { 'nodeType': 11 }; return { 'nodeType': 11 };
}); });
// fake `WinRTError` // fake `WinRTError`
setProperty(global, 'WinRTError', Error); setProperty(root, 'WinRTError', Error);
// add extensions // add extensions
Function.prototype._method = _.noop; Function.prototype._method = _.noop;
@@ -380,6 +382,10 @@
var _contains = String.prototype.contains; var _contains = String.prototype.contains;
setProperty(String.prototype, 'contains', _contains ? _.noop : Boolean); setProperty(String.prototype, 'contains', _contains ? _.noop : Boolean);
var _Float64Array = root.Float64Array;
if (!_Float64Array) {
setProperty(root, 'Float64Array', root.Uint8Array);
}
// clear cache so Lo-Dash can be reloaded // clear cache so Lo-Dash can be reloaded
emptyObject(require.cache); emptyObject(require.cache);
@@ -401,8 +407,11 @@
} else { } else {
delete String.prototype.contains; delete String.prototype.contains;
} }
delete global.window; if (!_Float64Array) {
delete global.WinRTError; delete root.Float64Array;
}
delete root.window;
delete root.WinRTError;
delete Function.prototype._method; delete Function.prototype._method;
}()); }());
@@ -515,11 +524,11 @@
} }
}); });
test('should avoid overwritten native methods', 9, function() { test('should avoid overwritten native methods', 11, function() {
function Foo() {} function Foo() {}
function message(methodName) { function message(methodName) {
return '`_.' + methodName + '` should avoid overwritten native methods'; return '`' + methodName + '` should avoid overwritten native methods';
} }
var object = { 'a': 1 }, var object = { 'a': 1 },
@@ -587,9 +596,23 @@
actual = null; actual = null;
} }
strictEqual(actual, true, message('String#contains')); strictEqual(actual, true, message('String#contains'));
if (root.Uint8Array) {
try {
var array = new Uint8Array(new ArrayBuffer(8));
actual = lodashBizarro.clone(array);
} catch(e) {
actual = null;
}
deepEqual(actual, array, message('Float64Array'));
notStrictEqual(actual, array, message('Float64Array'));
}
else {
skipTest(2);
}
} }
else { else {
skipTest(9); skipTest(11);
} }
}); });
}()); }());
@@ -4847,7 +4870,7 @@
var expected = !body; var expected = !body;
strictEqual(_.isElement(new Element), expected); strictEqual(_.isElement(new Element), expected);
if (lodashBizarro) { if (lodashBizarro && document) {
strictEqual(lodashBizarro.isElement(new Element), !expected); strictEqual(lodashBizarro.isElement(new Element), !expected);
} }
else { else {