Vue · Senior · Question 46 of 75
How do you test a composable that uses lifecycle hooks or inject?
- ✓Correct answer: Call it inside a small host component mounted in the test (or a helper that does this)
- 2Call it directly in the test - hooks work without a component
- 3Composables can't be tested
Explanation
Composables that only use reactivity can be called directly. Those needing an instance require a component context; provide values can be passed via global.provide in Vue Test Utils.