-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
p3-minor-bugAn edge case that only affects very specific usage (priority)An edge case that only affects very specific usage (priority)upstream
Description
Describe the bug
I hope I gave the right title.
Problem
Consider the following:
import { spyOn } from 'tinyspy'
class A {
_a = 0
get a() {
return this._a
}
set a(value) {
this._a = value
}
}
class Foo extends A {
}
const a = new Foo()
spyOn(a, { getter: 'a' }, () => 100)
console.log(a.a) // OK
a.a = 2 // fails here <----with error: TypeError: Cannot set property a of #<Foo> which has only a getter.
Looked at this function, and it this code:
let objDescriptor = getDescriptor(obj, accessName)
let proto = Object.getPrototypeOf(obj)
let protoDescriptor = proto && getDescriptor(proto, accessName)
let originalDescriptor = objDescriptor || protoDescriptor
assert(
originalDescriptor || accessName in obj,
`${String(accessName)} does not exist`
)originalDescriptor will be undefined but accessName in obj is true.
Works good if I do const a = new A() instead, but this is not the point.
Solution
I've investigated it, and saw that the problem is within https://github.com/tinylibs/tinyspy
I've opened an issue there tinylibs/tinyspy#49 and suggested a fix: tinylibs/tinyspy#50
But the team is probably busy with more urgent stuff.
Reproduction
Check PR tinylibs/tinyspy#50 in https://github.com/tinylibs/tinyspy it has a test that will fail.
Also this: https://stackblitz.com/edit/vitest-dev-vitest-qxyq6eqp?file=src%2Fbasic.ts
System Info
System:
OS: macOS 15.4
CPU: (10) arm64 Apple M1 Pro
Memory: 3.45 GB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 22.14.0 - ~/.nvm/versions/node/v22.14.0/bin/node
npm: 10.9.2 - ~/.nvm/versions/node/v22.14.0/bin/npm
pnpm: 10.7.1 - ~/Library/pnpm/pnpm
Browsers:
Chrome: 135.0.7049.41
Safari: 18.4
npmPackages:
vite: ^6.2.4 => 6.2.4
vitest: ^3.1.1 => 3.1.1Used Package Manager
npm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
p3-minor-bugAn edge case that only affects very specific usage (priority)An edge case that only affects very specific usage (priority)upstream