Skip to content

fix: reconcile the overridden prototype of component and _Vue mocks and mixins #912

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

Closed
wants to merge 1 commit into from

Conversation

kuitos
Copy link
Contributor

@kuitos kuitos commented Aug 10, 2018

fixed #889
@eddyerburgh please make a review

@kuitos
Copy link
Contributor Author

kuitos commented Aug 18, 2018

@eddyerburgh could you please donate some time to review it?

@eddyerburgh
Copy link
Member

Yes, I was intending to look at it today 👍

// we need change the proto chains manually
// @see https://github.com/vuejs/vue-test-utils/pull/856
const root = getRootVueProto(extendedComponent.prototype)
Object.setPrototypeOf(root, _Vue.prototype)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this would mutate components:

const CompA = Vue.extend()
const CompB = CompA.extend().extend()
const savedProto = CompA.prototype.__proto__
const rootProto = CompB.prototype.__proto__.__proto__
Object.setPrototypeOf(rootProto, null)

console.log(savedProto === CompA.prototype.__proto__) // false

Copy link
Contributor Author

@kuitos kuitos Aug 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it could if you set the proto of rootProto to be null.
But here we actually did was Object.setPrototypeOf(rootProto, _Vue.prototype)

const rootProto = CompB.prototype.__proto__.__proto__
Object.setPrototypeOf(rootProto, Vue.prototype)

console.log(savedProto === CompA.prototype.__proto__) // true

Copy link
Member

@eddyerburgh eddyerburgh Aug 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you set it to _Vue then I think it would still mutate the protoype, it just wouldn't be as severe:

const CompA = Vue.extend()
const CompB = CompA.extend().extend()
const _Vue = Vue.extend()

const savedProto = CompA.prototype.__proto__
const rootProto = CompB.prototype.__proto__.__proto__
Object.setPrototypeOf(rootProto, _Vue.prototype)

console.log(savedProto === CompA.prototype.__proto__) // false

Copy link
Contributor Author

@kuitos kuitos Aug 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with what you concerned about, I will add an unit test and find a way to guarantee the super component immutably.
What do you think? Any suggestion? :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be great, I don't have any suggestions unfortunately. I spent some time two weeks ago investigating, but I couldn't find a solution that didn't mutate the original components

@kuitos kuitos closed this Nov 2, 2019
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 this pull request may close these issues.

2 participants