source: imaps-frontend/node_modules/is-data-view/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
RevLine 
[d565449]1'use strict';
2
3var test = require('tape');
4var isDataView = require('../');
5
6var hasToStringTag = require('has-tostringtag/shams')();
7var generators = require('make-generator-function')();
8var arrowFns = require('make-arrow-function').list();
9var forEach = require('for-each');
10var v = require('es-value-fixtures');
11var inspect = require('object-inspect');
12var availableTypedArrays = require('available-typed-arrays')();
13
14test('not DataViews', function (t) {
15 forEach([].concat(
16 // @ts-expect-error TS sucks at [].concat
17 v.primitives,
18 v.objects,
19 function () {},
20 generators,
21 arrowFns,
22 []
23 ), /** @type {(nonDV: unknown) => void} */ function (nonDV) {
24 t.equal(
25 isDataView(nonDV),
26 false,
27 inspect(nonDV) + ' is not a DataView'
28 );
29 });
30
31 forEach(availableTypedArrays, function (typedArray) {
32 var TA = global[typedArray];
33 var ta = new TA(8);
34 t.equal(isDataView(ta), false, inspect(ta) + ' is not a DataView');
35 });
36
37 t.end();
38});
39
40test('@@toStringTag', { skip: !hasToStringTag }, function (t) {
41 forEach(availableTypedArrays, function (typedArray) {
42 // @ts-expect-error
43 var fakeTypedArray = [];
44 // @ts-expect-error
45 fakeTypedArray[Symbol.toStringTag] = typedArray;
46 // @ts-expect-error
47 t.notOk(isDataView(fakeTypedArray), 'faked ' + typedArray + ' is not typed array');
48 });
49
50 t.end();
51});
52
53test('Data Views', { skip: typeof DataView !== 'function' }, function (t) {
54 var ab = new ArrayBuffer(1);
55 var dv = new DataView(ab);
56
57 t.equal(isDataView(dv), true, inspect(dv) + ' is a DataView');
58
59 t.end();
60});
Note: See TracBrowser for help on using the repository browser.