tests.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. 'use strict';
  2. var hasSymbols = require('has-symbols')();
  3. module.exports = function runTests(hasOwn, t) {
  4. var badPropertyKey = { toString: function () { throw new SyntaxError('nope'); } };
  5. t['throws'](
  6. function () { hasOwn(null, badPropertyKey); },
  7. TypeError,
  8. 'checks ToObject first'
  9. );
  10. t['throws'](
  11. function () { hasOwn({}, badPropertyKey); },
  12. SyntaxError,
  13. 'checks ToPropertyKey next'
  14. );
  15. var obj = { a: 1 };
  16. t.equal('toString' in obj, true, 'object literal has non-own toString');
  17. t.equal(hasOwn(obj, 'toString'), false, 'toString is not an own property');
  18. t.equal(hasOwn(obj, 'a'), true, 'own property is recognized');
  19. t.equal(hasOwn([], 'length'), true, 'non-enumerable own property is recognized');
  20. t.test('Symbols', { skip: !hasSymbols }, function (st) {
  21. var o = {};
  22. o[Symbol.iterator] = true;
  23. st.equal(hasOwn(o, Symbol.iterator), true, 'own symbol is recognized');
  24. st.equal(hasOwn(Array.prototype, Symbol.iterator), true, 'built-in own symbol is recognized');
  25. st.end();
  26. });
  27. };