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

watch mounting option should overwrite option on same component #1391

Closed
lmiller1990 opened this issue Jan 6, 2020 · 0 comments · Fixed by #1392
Closed

watch mounting option should overwrite option on same component #1391

lmiller1990 opened this issue Jan 6, 2020 · 0 comments · Fixed by #1392
Assignees
Labels

Comments

@lmiller1990
Copy link
Member

lmiller1990 commented Jan 6, 2020

Version

1.0.0-beta.30

Reproduction link

https://i-included-a-repro.com

Steps to reproduce

repro

import { mount, shallowMount } from '@vue/test-utils'

const Comp = {
  template: '<div />',
  props: ['myProp'],
  watch: {
    myProp: {
      handler(val, oldVal) {
        console.log('Original watcher triggered!')
      },
      deep: true
    }
  }
}

test('Both watchers trigger', (done) => {
  const wrapper = mount(Comp, {
    propsData: {
      myProp: 'foo'
    },
    watch: {
      myProp: {
        handler(val, oldVal) {
          console.log('Overridden watcher triggered!')
        },
        deep: true
      }
    }
  })

  wrapper.setProps({ myProp: 'ok' })

  setTimeout(() => {
    done()
  }, 100)
})

What is expected?

Only the mounting options watcher should do anything.

What is actually happening?

Both watchers are triggered.


This is because of this line here which uses Vue's watcher merge strategy, which is to create an array of watchers. That code is in Vue core, found here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant