question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Testing of computed properties

See original GitHub issue

When trying to test a computed property using AVA and with Avoriaz, the context of this is not what is expected. I’m trying to use a computed property that is based on some data from the component.

More details on stackoverflow.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:14 (11 by maintainers)

github_iconTop GitHub Comments

4reactions
eddyerburghcommented, Mar 30, 2017

@jasperck Hi, sorry for the miselading message. I’ve updated and released a correct warning message in 1.9.4.

To access props with this bound the vue instance, you must run:

expect(wrapper.vm.$props.propName).to.equal(propValue);
1reaction
jasperckcommented, Mar 30, 2017

hi @eddyerburgh I was writing tests for my vue component, when I tried to test the part of props, I was doing something like this

given(
  ...some test data
)
  .it('should accept prop:', (propName, propValue) => {
    const wrapper = mount(InfiniteScroller, {
      propsData: { propName: propValue }
    });
    expect(wrapper.propsData().propName).to.equal(propValue);
  });

Then I got this warning messages and found out the reason in the issue from the messages.

WARN: 'warning: functions returned by propsData() will not have this bound to the vue instance. Calling a propsData function that uses this will result in an error. You can access propsData functions by using the vue instance. e.g. to call a method function named propsDataFunc, call wrapper.vm.propsDataFunc(). See https://github.com/eddyerburgh/avoriaz/issues/15'

According to the comment https://github.com/eddyerburgh/avoriaz/issues/15#issuecomment-289435469, looks like there is still no solution for somethink like

expect(wrapper.vm.propName).to.equal(propValue);

am I right, guys?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Computed Properties - Vue Testing Handbook
Let's start with looking at two different ways to test a computed property. We will develop a <NumberRenderer> component, that renders ...
Read more >
Test Computed Properties and Watchers in Vue.js ... - Alex Jover
Testing a computed property is very simple, and probably sometimes you don't test a computed property exclusively, but test it as part of ......
Read more >
how can i test a computed property in vuejs using jest?
im still new with unit testing and i want to test if the a linked button is displayed when the isLinkPresent computed property...
Read more >
Learn How To Test Computed Properties and Watchers
In this lesson, we'll learn how to test one of our favorite features of Vue.js, computed properties, and watchers. There is also a...
Read more >
Computed Properties - Testing Vue.js Components with Jest
Testing a computed property is very simple, and sometimes we don't test a computed property exclusively but test it as part of other...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found