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

Easier way to instantiate a component with data #55

Closed
aidangarza opened this issue Jun 12, 2017 · 1 comment
Closed

Easier way to instantiate a component with data #55

aidangarza opened this issue Jun 12, 2017 · 1 comment
Milestone

Comments

@aidangarza
Copy link

aidangarza commented Jun 12, 2017

I have a test for a watcher that aims to test the outcome of a data property changing from one non-initial value to another non-initial value, e.g.

{
  data () {
    return {
      gid: null
    }
  },

  watch: {
    gid (newVal, oldVal) {
      if (oldVal) { /* Do B */ }
      if (newVal) { /* Do A */ }
    }
  }
}

The test wants to see the outcome of /* Do B */. Obviously, this can be done by mounting the component, changing the value, waiting for next tick, changing the value again, waiting for next tick again, and then making the assertion. Another way that I've done this is by using the before option, e.g.

describe('gid watcher', () => {
  it('should Do A and Do B when gid changes from an existing value to a new existing value', async () => {
    let before = (component) => {
      let data = component.data()
      component.data = () => ({ ...data, gid: 123 })
    }
    let vm = shallow(Component, { before })

    vm.gid = 321

    await vm.$nextTick()

    expect(/* to have done A and B */)
  })
})

All of this works fine, but it seems like there should be an easier way to set initial data values to test individual watchers and methods.

@jackmellis
Copy link
Owner

I think this is a good idea, a simple data option would do the trick and would be pretty simple to implement (similar to your before method).

Unfortunately I only just published 0.5 yesterday!

@jackmellis jackmellis added this to the 0.6.0 milestone Jun 13, 2017
jackmellis pushed a commit that referenced this issue Jun 13, 2017
jackmellis added a commit that referenced this issue Jun 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants