hatch-surf/node_modules/own-keys/test/index.js
Riley Zhang df378d33ef
Some checks failed
CI / go (push) Waiting to run
CI / docker (push) Waiting to run
CI / lint-go (push) Waiting to run
CI / lint-docs (push) Waiting to run
CI / check-paperclip (push) Waiting to run
Deploy static site / Deploy to GitHub Pages (push) Has been cancelled
Deploy static site / Deploy via Docker to hatch.surf (push) Has been cancelled
Merge GitHub main into Gitea repo (allow unrelated histories)
Resolved conflicts by taking GitHub versions for:
- .dockerignore, .gitignore, Dockerfile, README.md, docker-compose.yml

Kept deploy.sh updated to:
- Pull from GitHub (primary source)
- Push to Gitea (push-mirror)
- Build from site/ directory (GitHub structure)

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-06-25 05:20:46 +02:00

73 lines
1.5 KiB
JavaScript

'use strict';
var test = require('tape');
var hasSymbols = require('has-symbols/shams')();
var hasPropertyDescriptors = require('has-property-descriptors')();
var ownKeys = require('../');
/** @type {(a: PropertyKey, b: PropertyKey) => number} */
function comparator(a, b) {
if (typeof a === 'string' && typeof b === 'string') {
return a.localeCompare(b);
}
if (typeof a === 'number' && typeof b === 'number') {
return a - b;
}
return typeof a === 'symbol' ? 1 : -1;
}
test('ownKeys', function (t) {
t.equal(typeof ownKeys, 'function', 'is a function');
t.equal(
ownKeys.length,
1,
'has a length of 1'
);
t.test('basics', function (st) {
var obj = { a: 1, b: 2 };
if (hasPropertyDescriptors) {
Object.defineProperty(obj, 'c', {
configurable: true,
enumerable: false,
writable: true,
value: 3
});
}
st.deepEqual(
ownKeys(obj).sort(comparator),
(hasPropertyDescriptors ? ['a', 'b', 'c'] : ['a', 'b']).sort(comparator),
'includes non-enumerable properties'
);
st.end();
});
t.test('symbols', { skip: !hasSymbols }, function (st) {
/** @type {Record<PropertyKey, unknown>} */
var obj = { a: 1 };
var sym = Symbol('b');
obj[sym] = 2;
var nonEnumSym = Symbol('c');
Object.defineProperty(obj, nonEnumSym, {
configurable: true,
enumerable: false,
writable: true,
value: 3
});
st.deepEqual(
ownKeys(obj).sort(comparator),
['a', sym, nonEnumSym].sort(comparator),
'works with symbols, both enum and non-enum'
);
st.end();
});
t.end();
});