eddyerburgh / avoriaz

🔬 a Vue.js testing utility library
https://eddyerburgh.gitbooks.io/avoriaz/content/
MIT License
759 stars 62 forks source link

setProps and setData should return this #115

Open hauleth opened 7 years ago

hauleth commented 7 years ago

This would allow chaining methods in tests and in future would simplify migration to immutable VueWrapper.

Example:

  it('contains value of `greeting` prop', () => {
    const wrapper = mount(Hello)

    wrapper.setProps({greeting: 'Yay!'})

    expect(wrapper.text()).toBe('Yay!')
  })

Could be written as:

  it('contains value of `greeting` prop', () => {
    const wrapper = mount(Hello)

    expect(wrapper.setProps({greeting: 'Yay!'}).text()).toBe('Yay!')
  })
eddyerburgh commented 7 years ago

Hi @hauleth .

Personally I'm not a fan of chaining methods, but I can be convinced. If other users would benefit from this feature, then I would be happy to accept a PR implementing the changes

hauleth commented 7 years ago

The whole point is to have immutable wrappers in future that would allow writing code like:

const wrapper = mount(Hello)

it('contains default greeting', () => {
  expect(wrapper.text()).toBe('Hello World!')
})

it('contains value of `greeting` prop', () => {
  expect(wrapper.setProps({greeting: 'Witaj Świecie!'}).text()).toBe('Witaj Świecie!')
})

Instead of creating new wrapper inside each test.