index.js 751 B

1234567891011121314151617181920212223242526
  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 byteLength = require('../');
  7. test('byteLength', function (t) {
  8. forEach(v.objects.concat(v.primitives), function (nonAB) {
  9. t.equal(byteLength(nonAB), NaN, inspect(nonAB) + ' is not an ArrayBuffer, and yields NaN');
  10. });
  11. t.test('ArrayBuffers', { skip: typeof ArrayBuffer !== 'function' }, function (st) {
  12. var ab32 = new ArrayBuffer(32);
  13. st.equal(byteLength(ab32), 32, 'works on an ArrayBuffer of length 32: ' + inspect(ab32));
  14. var ab0 = new ArrayBuffer(0);
  15. st.equal(byteLength(ab0), 0, 'works on an ArrayBuffer of length 0: ' + inspect(ab0));
  16. st.end();
  17. });
  18. t.end();
  19. });