test(context): assert scope isolation without probing prototypes

Replace Object.getPrototypeOf checks for bottom() and getAll() with
'in' checks on typical Object.prototype names plus a merge assertion.

Co-authored-by: Cursor <[email protected]>
This commit is contained in:
Yang Jun
2026-05-13 01:06:51 +08:00
co-authored by Cursor
parent 8a3634a3cb
commit bf3a06fe23
+9 -4
View File
@@ -217,11 +217,16 @@ describe('Context', function () {
})
})
describe('scope storage', function () {
it('should use null prototype for bottom scope', function () {
expect(Object.getPrototypeOf(new Context().bottom())).toBeNull()
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 use null prototype for getAll() merge result', function () {
expect(Object.getPrototypeOf(new Context({ a: 1 }).getAll())).toBeNull()
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)
})
})
})