Skip to content

setData() doesn't trigger watcher #149

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

Closed
darrenjennings opened this issue Nov 3, 2017 · 7 comments
Closed

setData() doesn't trigger watcher #149

darrenjennings opened this issue Nov 3, 2017 · 7 comments
Labels

Comments

@darrenjennings
Copy link

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();
  });
});
@eddyerburgh
Copy link
Member

Thanks for the bug report 😀

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

@beliolfa
Copy link

beliolfa commented Nov 7, 2017

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

@eddyerburgh
Copy link
Member

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

@blake-newman
Copy link
Member

@eddyerburgh has the setComputed been fixed already?

@blake-newman
Copy link
Member

If not then i'll open an issue

@beliolfa
Copy link

beliolfa commented Dec 7, 2017

+1

@eddyerburgh
Copy link
Member

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 🙂

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

No branches or pull requests

4 participants