Vue3.2 Computed

Posted on  by admin

Modified1 month ago. I am trying to write a test, using vitest, to assert a computed property in a vue3 component that is defined with script setup.

Conclusion

Consider a simple component:. My test is like this:. This test actually works as expected when run using vitest, so functionally things seem to be working well.

However, VSCode cannot see the computed properties on the vm object:. It is able to see normal properties (e.g., those defined with the defineProps macro).

Methods

Is this just a problem with VSCode-specific tooling, or is there another way I should be going about testing computed properties in vue3 components?

  • If this is the preferred method, is there a way to pull in the types of the computed properties (similar to how the types of the defined props seem to be pulled in)?
  • I have tried the technique described in this Vue Testing Handbook, but this doesn't work at all and I assume it must be specific to vue2.

199199 bronze badges. 11.1k33 gold badges3535 silver badges5656 bronze badges. 3535 silver badges5656 bronze badges.

Components using