index.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. 'use strict';
  2. var test = require('tape');
  3. var setProto = require('../');
  4. var isPrototypeOf = Object.prototype.isPrototypeOf;
  5. test('setProto', function (t) {
  6. t.equal(typeof setProto, 'function', 'is a function');
  7. t.test('can set', { skip: !setProto }, function (st) {
  8. var obj = { a: 1 };
  9. var proto = { b: 2 };
  10. st.ok(isPrototypeOf.call(Object.prototype, obj), 'Object.prototype is isPrototypeOf obj');
  11. st.notOk(isPrototypeOf.call(proto, obj), 'proto is not isPrototypeOf obj');
  12. st.ok('a' in obj, 'a is in obj');
  13. st.notOk('b' in obj, 'b is not in obj');
  14. // eslint-disable-next-line no-extra-parens
  15. st.equal(/** @type {NonNullable<typeof setProto>} */ (setProto)(obj, proto), obj, 'returns the object');
  16. st.ok(isPrototypeOf.call(Object.prototype, obj), 'Object.prototype is isPrototypeOf obj');
  17. st.ok(isPrototypeOf.call(proto, obj), 'proto is isPrototypeOf obj');
  18. st.ok('a' in obj, 'a is in obj');
  19. st.ok('b' in obj, 'b is in obj');
  20. st.equal(Object.getPrototypeOf(obj), proto, 'sets the prototype');
  21. st.end();
  22. });
  23. t.test('can not set', { skip: !!setProto }, function (st) {
  24. st.equal(setProto, null);
  25. st.end();
  26. });
  27. t.end();
  28. });