index.js 1.5 KB

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