source: imaps-frontend/node_modules/is-array-buffer/test/index.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.5 KB
Line 
1'use strict';
2
3var test = require('tape');
4var inspect = require('object-inspect');
5var forEach = require('for-each');
6var v = require('es-value-fixtures');
7var availableTypedArrays = require('available-typed-arrays')();
8
9var isArrayBuffer = require('..');
10
11test('isArrayBuffer', function (t) {
12 t.equal(typeof isArrayBuffer, 'function', 'is a function');
13
14 /** @type {unknown[]} */
15 var nonABs = [].concat(
16 // @ts-expect-error TS sucks with [].concat
17 v.primitives,
18 v.objects,
19 typeof SharedArrayBuffer === 'function' ? new SharedArrayBuffer(0) : []
20 );
21 forEach(nonABs, function (nonAB) {
22 t.equal(isArrayBuffer(nonAB), false, inspect(nonAB) + ' is not an ArrayBuffer');
23 });
24
25 t.test('actual ArrayBuffer instances', { skip: typeof ArrayBuffer === 'undefined' }, function (st) {
26 // @ts-expect-error TS grumbles about 0 args
27 var ab = new ArrayBuffer();
28 st.equal(isArrayBuffer(ab), true, inspect(ab) + ' is an ArrayBuffer');
29
30 var ab42 = new ArrayBuffer(42);
31 st.equal(isArrayBuffer(ab42), true, inspect(ab42) + ' is an ArrayBuffer');
32
33 var dv = new DataView(ab42);
34 st.equal(isArrayBuffer(dv), false, inspect(dv) + ' is not an ArrayBuffer');
35
36 st.end();
37 });
38
39 t.test('Typed Arrays', { skip: availableTypedArrays.length === 0 }, function (st) {
40 forEach(availableTypedArrays, function (TypedArray) {
41 var ta = new global[TypedArray](0);
42 st.equal(isArrayBuffer(ta.buffer), true, inspect(ta.buffer) + ', the TA\'s buffer, is an ArrayBuffer');
43 st.equal(isArrayBuffer(ta), false, inspect(ta) + ' is not an ArrayBuffer');
44 });
45
46 st.end();
47 });
48
49 t.end();
50});
Note: See TracBrowser for help on using the repository browser.