test(context): cover Object.prototype keys under ownPropertyOnly

- Add getSync cases for constructor and valueOf on plain objects
- Remove scope storage tests that used the in operator

Co-authored-by: Cursor <[email protected]>
This commit is contained in:
Yang Jun
2026-05-14 02:23:08 +08:00
co-authored by Cursor
parent 56d1fa84f4
commit ac683a917b
+5 -13
View File
@@ -138,6 +138,11 @@ describe('Context', function () {
ctx.push({ foo: [] })
return expect(ctx.getSync(['foo', 'reduce'])).toEqual(undefined)
})
it('should return undefined for typical Object.prototype properties (e.g. constructor, valueOf)', function () {
ctx.push({ obj: {} })
expect(ctx.getSync(['obj', 'constructor'])).toEqual(undefined)
expect(ctx.getSync(['obj', 'valueOf'])).toEqual(undefined)
})
it('should return undefined for function prototype property', function () {
function Foo () {}
Foo.prototype.bar = 'BAR'
@@ -216,17 +221,4 @@ describe('Context', function () {
expect(ctx.getSync(['foo'])).toEqual('zoo')
})
})
describe('scope storage', function () {
it('should not treat Object.prototype properties as implicit keys on bottom scope', function () {
const bottom = new Context().bottom() as Record<string, unknown>
expect('toString' in bottom).toBe(false)
expect('hasOwnProperty' in bottom).toBe(false)
})
it('should merge into a scope result without implicit Object.prototype keys', function () {
const all = new Context({ a: 1 }).getAll() as Record<string, unknown>
expect(all.a).toBe(1)
expect('toString' in all).toBe(false)
expect('hasOwnProperty' in all).toBe(false)
})
})
})