Vue-test-utils: setData() doesn't trigger watcher

Created on 3 Nov 2017  路  7Comments  路  Source: vuejs/vue-test-utils

I have a component that watches a data object suggestions. When I mount the component and then call wrapper.setData({ suggestions: [] }); the watcher does not fire, as I put a console.log on the watcher to verify. If I set the watcher to be "immediate: true" then it will fire once. Is there something else I should do to trigger the watcher in a testing environment? I tried wrapper.vm.$nextTick to no avail.

const defaultProps = {
  suggestions: [
    {
      data: ["clifford kits", "friendly chemistry", "phonics"]
    }
  ],
  inputProps: {
    id: "autosuggest__input"
  }
};

it("can render suggestions", async () => {
  const wrapper = mount(Autosuggest, {
    propsData: defaultProps
  });

  const input = wrapper.find("input");
  expect(input.hasAttribute("id", defaultProps.inputProps.id));

  input.trigger("click");
  wrapper.setData({
    searchInput: "G",
    suggestions: [
      {
        data: ["friendly chemistry", "phonics"]
      }
    ]
  });
  input.trigger("keydown.down");

  const renderer = createRenderer();
  renderer.renderToString(wrapper.vm, (err, str) => {
    expect(str).toMatchSnapshot();
  });
});

bug

Most helpful comment

Sorry for the delay guys, I saw this an forgot to reply.

I've updated setComputed to run the correct watchers. It'll be released in beta.7 in the next couple of days 馃檪

All 7 comments

Thanks for the bug report 馃榾

I've added a fix in the dev branch. It will be released in beta.5

Same issue here using setComputed(). It is related?

Yes :P, sorry. Can you make a new issue @disitec

@eddyerburgh has the setComputed been fixed already?

If not then i'll open an issue

+1

Sorry for the delay guys, I saw this an forgot to reply.

I've updated setComputed to run the correct watchers. It'll be released in beta.7 in the next couple of days 馃檪

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vilarinholeo picture vilarinholeo  路  3Comments

yoyoys picture yoyoys  路  3Comments

chenxeed picture chenxeed  路  3Comments

matt-sanders picture matt-sanders  路  3Comments

jonyoder picture jonyoder  路  3Comments