Skip to content

Commit 792d5f8

Browse files
committed
Add tests for the new exported type checkers (#2694)
1 parent f539ebf commit 792d5f8

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

test/objects.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,42 @@
911911
assert.ok(_.isError(new URIError()), 'URIErrors are Errors');
912912
});
913913

914+
if (typeof ArrayBuffer != 'undefined') {
915+
QUnit.test('isArrayBuffer, isDataView and isTypedArray', function(assert) {
916+
var buffer = new ArrayBuffer(16);
917+
var checkValues = {
918+
'null': null,
919+
'a string': '',
920+
'an array': [],
921+
'an ArrayBuffer': buffer,
922+
'a DataView': new DataView(buffer),
923+
'a TypedArray': new Uint8Array(buffer)
924+
};
925+
var types = ['an ArrayBuffer', 'a DataView', 'a TypedArray'];
926+
_.each(types, function(type) {
927+
var typeCheck = _['is' + type.split(' ')[1]];
928+
_.each(checkValues, function(value, description) {
929+
if (description === type) {
930+
assert.ok(typeCheck(value), description + ' is ' + type);
931+
} else {
932+
assert.ok(!typeCheck(value), description + ' is not ' + type);
933+
}
934+
});
935+
});
936+
});
937+
938+
QUnit.test('isTypedArray', function(assert) {
939+
var buffer = new ArrayBuffer(16);
940+
_.each([Uint8ClampedArray, Int8Array, Uint16Array, Int16Array, Uint32Array, Int32Array, Float32Array, Float64Array], function(ctor) {
941+
assert.ok(_.isTypedArray(new ctor(buffer)), ctor.name + ' is a typed array');
942+
});
943+
944+
if (typeof BigInt64Array != 'undefined') {
945+
assert.ok(_.isTypedArray(new BigInt64Array(buffer)), 'BigInt64Array is a typed array');
946+
}
947+
});
948+
}
949+
914950
QUnit.test('tap', function(assert) {
915951
var intercepted = null;
916952
var interceptor = function(obj) { intercepted = obj; };

0 commit comments

Comments
 (0)