Skip to content
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

spy.on doesn't work with nullish prototype #117

Closed
sebamarynissen opened this issue Apr 5, 2023 · 0 comments · Fixed by #118
Closed

spy.on doesn't work with nullish prototype #117

sebamarynissen opened this issue Apr 5, 2023 · 0 comments · Fixed by #118

Comments

@sebamarynissen
Copy link
Contributor

I've noticed that if you do something like

const object = Object.create(null);
object.method = function() {};
chai.spy.on(object, 'method');

it will throw an error because it uses

object.hasOwnProperty(methodName);

This can be fixed easily by changing it to

Object.hasOwnProperty.call(object, methodName);

I will file a PR for this.

Context

I've encountered the issue in the context of migrating to Vue 3 and using @vue/test-utils. Apparently if you mount a component like

import { mount } from '@vue/test-utils';
let { vm } = mount(Component);

then vm is an object with null as its prototype. If you then want to spy on some of its methods with chai.spy.on, it throws the error above.

sebamarynissen added a commit to sebamarynissen/chai-spies that referenced this issue Apr 5, 2023
keithamus added a commit that referenced this issue Apr 6, 2023
Fixes #117.

Co-authored-by: Keith Cirkel <keithamus@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant