tinylibs/tinyspy

Cannot spy on methods inherited from prototype chain. e.g. document.head.appendChild

JessicaSachs opened this issue ยท 2 comments

๐Ÿ‘‹๐Ÿป I'm migrating some tests for VueUse and ran into an issue where spying on document.head.appendChild (removeChild, etc) was throwing errors.

Screen Shot 2021-12-20 at 10 26 54 PM

Currently, the logic for detecting if you can spy on a method/value is based on if you can get the object's descriptor.

This isn't accessible via document.head's own property descriptor. Other libraries don't rely on getting the descriptor and instead always fallback to simply looking up the value via document.head['appendChild'] (this is what nanospy does) or something similar (Sinon's implementation is a bit more complex, but it falls back to looking up the property directly).

I put a mini-repro together here. You can open it via yarn vite.

Should be fixed in 0.2.4

Nice, LGTM!