index.js 959 B

12345678910111213141516171819202122232425262728293031
  1. 'use strict';
  2. var test = require('tape');
  3. var forEach = require('for-each');
  4. var v = require('es-value-fixtures');
  5. var inspect = require('object-inspect');
  6. var dataViewBuffer = require('../');
  7. test('dataViewBuffer', function (t) {
  8. forEach(
  9. // @ts-expect-error TS sucks at [].concat
  10. // eslint-disable-next-line no-extra-parens
  11. /** @type {[...typeof v.primitives, ...typeof v.objects]} */ ([].concat(v.primitives, v.objects)),
  12. function (nonDV) {
  13. t['throws'](function () { dataViewBuffer(nonDV); }, TypeError, inspect(nonDV) + ' is not a DataView');
  14. }
  15. );
  16. t.test('DataView', { skip: typeof DataView !== 'function' }, function (st) {
  17. var ab = new ArrayBuffer(1);
  18. var dv = new DataView(ab);
  19. st.equal(dataViewBuffer(dv), ab, inspect(dv) + ' has the same buffer originally passed to the DataView');
  20. st.equal(dataViewBuffer(dv), dv.buffer, inspect(dv) + ' has the same buffer as its own buffer property');
  21. st.end();
  22. });
  23. t.end();
  24. });