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

data() unreachable for components using Vuelidate #795

Closed
SzNagyMisu opened this issue Jul 3, 2018 · 2 comments
Closed

data() unreachable for components using Vuelidate #795

SzNagyMisu opened this issue Jul 3, 2018 · 2 comments

Comments

@SzNagyMisu
Copy link

Version

1.0.0-beta.18

Reproduction link

https://codesandbox.io/s/5lrvnoynx

Steps to reproduce

When upgrading from 1.0.0-beta.17 (up to 1.0.0-beta.20 I tried), all my components that use vuelidate are unable to reach data(). If I try and test if the initial values are correctly set, I get an error message.

What is expected?

the properties of vm.$options.data() should be available for testing

What is actually happening?

data() cannot be reached

@LinusBorg
Copy link
Member

LinusBorg commented Jul 4, 2018

I'm trying to understand your reproduction, but I can't follow. The two tests that it contains seems to be meant to pass if said error is thrown, but they fail for some other error. Not good for a reproduction.

But I tried to investigate nonetheless.

  • Vuelidate adds a mixin that relies on this in the data function to be a component instance.
  • calling the data function on its own directly does not do that.
  • calling it like this works: vm.$options.data.call(vm) or data.call(vm)

This is not related to vue-test-utils in any way. If you do the following in main.js you get the same error:

const main = new Vue({
  el: "#app",
  components: { App },
  template: '<App ref="app"/>'
});

console.log(main.$refs.app.$options.data())

grafik

...while the following works:

const main = new Vue({
  el: "#app",
  components: { App },
  template: '<App ref="app"/>'
});

console.log(main.$refs.app.$options.data.call(main.$refs.app))

grafik

@SzNagyMisu
Copy link
Author

SzNagyMisu commented Jul 13, 2018

Thank you for having had a look on this issue.
Yes, I was pretty sure, it had to do mostly with vuelidate, the only thing intriguing me was that it does work if I use @vue/test-utils 1.0.0-beta.17 or below. Any idea what could have changed in test-utils, explaining this?

(BTW, I modified the reproduction to expect the test to work)

Thanks!

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

No branches or pull requests

2 participants