-
-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
1.1.0 breaks instanceOf tests #32
Comments
Doesn't seem to be intentional, @trivikr what do you think? |
The error in this case was: AssertionError: expected <Anonymous Class>{} to be an instance of MyClass I played around with |
The following solution fixes instance of checks: result = new.target
? new (fn.impl as any)(...args)
: fn.impl.apply(this, args)
if (new.target) Object.setPrototypeOf(r, this); @sheremet-va Would you like to attempt trying it out? |
What are the performance implications of this? |
I think we should follow Make it work, Make it right, Make it fast. In this case, the Make it work/right is not true as per #29 |
Only if it is really a bug. These revelations are leading me to believe that this is intended behavior. It is consistent with sinon and jest behaviors at least: import { stub } from "sinon";
import { ModuleMocker } from "jest-mock";
const obj = {
className: class Foo {},
};
stub(obj, "className").callsFake(function () {
console.log(new.target);
});
obj.className(); // undefined
new obj.className(); // undefined
const mocker = new ModuleMocker(global);
mocker.spyOn(obj, "className").mockImplementation(function () {
console.log(new.target);
});
obj.className(); // undefined
new obj.className(); // undefined |
@sheremet-va and @trivikr, Thank you for the quick response and turn around. |
Added a summary in #29 (comment) for future discussion about new.target |
I'm not sure if this was intended, but #31, breaks
instanceof
class.It is a bit of a contrived example. But I'm not sure how to preserve the inheritance chain.
Repo: https://github.com/Jason3S/tinyspy-issue-32
StackBlitz: https://stackblitz.com/edit/vitest-dev-vitest-dhhorq?file=README.md
The text was updated successfully, but these errors were encountered: