Open mikemonteith opened 10 months ago
Is this a vue thing?
I've just found that this gives me the behaviour I want:
const wrapper = mount(MessageComponent, {
global: {
config: {
errorHandler: (err) => {
throw err;
},
}
},
});
I've ended up adding this to our setup.js
file to set this behaviour in all tests.
import { config } from '@vue/test-utils';
// By default, vue will attempt to continue past setup errors.
// This will cause tests to fail silently, so we make sure that
// exceptions are thrown immediately in all tests.
config.global.config.errorHandler = (err) => {
throw err;
};
Maybe this could be more prominent in the docs?
@mikemonteith dude you saved my day. I was chasing false errors.
TypeError: Cannot read properties of undefined (reading 'map')
❯ src/views/SubscriptionSelectSkeleton.vue:12:33
10| <v-card-text>
11| <v-select
12| :items="subscriptions.map(({ fqdn, id, stackName }) =>
| ^
In my case I was accessing an undefined value in useRoute
in <script setup>
, which let to this error. subscriptions
was always a valid array.
Adding your code gave me the correct error output.
TypeError: Cannot read properties of undefined (reading '0')
❯ setup src/views/SubscriptionSelectSkeleton.vue:53:27
51| const route = useRoute()
52| const router = useRouter()
53| const path = route.matched[0].path
^
In hindsight it makes sense, because the actual function which defines subscriptions
was then never called.
@mikemonteith I think from the version of your package.json it seems you opened the issue on the wrong repository:
"@vue/test-utils": "^2.4.1"
This repository is for version 1 for the version 2: https://github.com/vuejs/test-utils/issues and the version you currently have: https://github.com/vuejs/test-utils/releases/tag/v2.4.1
@joaopedrodcf Well spotted. In that case, my issue is a duplicate of https://github.com/vuejs/test-utils/issues/2319
No problem glad to help ✌️
Subject of the issue
Errors thrown in
setup()
are silently caught if the render function throws it's own error. This can lead to confusing test error messages that seem like something is wrong in the template, when the issue is actually in the setup.Consider the reproduction case below:
Steps to reproduce
package.json:
test.js:
Expected behaviour
I would expect the program to stop when setup() throws the error.
Actual behaviour
The program continues by rendering the template with an empty context, which then throws it's own error due to
t
being undefined.Output: