Skip to content

Propogate thrown errors by configuring error handler and attaching in… #154

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

Merged
merged 3 commits into from
Nov 9, 2017

Conversation

Austio
Copy link
Contributor

@Austio Austio commented Nov 5, 2017

… mount function resolves #147

High level overview

Creates an errorHandler function which we assign to Vue's config.errorHandler. This errorHandler will be called with the error, the vm and additional info from vue. The error handler handles

  • thrown Error objects throw(new Error('error'))
  • thrown string object throw('error')
  • appending info to the error message if it is provided

Background/Justification

Currently vue-test-utils silently swallows errors that are thrown in components. This can lead to false green test suits. Proof of issue is in this repo pull request https://github.com/Austio/vue-test-utils-mocha-webpack-example/pull/1

const errorString = 'errorString'
const info = 'additional info provided by vue'

describe('with Error thrown', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove the nested describe blocks? Everywhere else the describe blocks aren't nested

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

throw new Error(errorMessage(err, info));
}

export {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you export the functions rather than an object that contains the functions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

src/mount.js Outdated

Vue.config.productionTip = false
setVueErrorHandler(Vue)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should export errorHandler and call Vue.config.errorHandler = errorHandler, instead of calling a function. Especially since we set productionTip false just above the function

Copy link
Contributor Author

@Austio Austio Nov 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member

@eddyerburgh eddyerburgh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, I'd just like to see a few style changes in the code. errorHandler should be a default export, and we should set Vue.config.errorHandler = errorHandler in mount

@Austio Austio force-pushed the as-propogate-errors branch from 33e2d4a to ca3e578 Compare November 6, 2017 03:09
@Austio Austio force-pushed the as-propogate-errors branch from ca3e578 to e43f9fc Compare November 6, 2017 03:18
@Austio
Copy link
Contributor Author

Austio commented Nov 6, 2017

@eddyerburgh should be good

I think something to consider is having a TestUtilsVue and import Vue from there when we are implementing things like mount, shallow, etc. It would allow us to centralize things that need to be set on each Vue instance globally (like the error handler)

@eddyerburgh
Copy link
Member

eddyerburgh commented Nov 6, 2017

When you import/ require in node it caches the instance, so every import to vue is the same vue constructor as every other require.

// some-file.js 
import Vue from 'vue'
Vue.config.errorHandler = true

// some-other-file.js 
import Vue from 'vue'
console.log(Vue.config.errorHandler) // true

So if I understood correctly, there's no need to centralize a Vue singleton, because node requires are always singletons (unless you explicitly delete the cache)

@eddyerburgh
Copy link
Member

Ah I just read your code, I see what you mean. We could add it in the createInstance—https://github.com/vuejs/vue-test-utils/blob/dev/src/lib/create-instance.js#L18. This is the same variable for localVue and for a regular Vue

@eddyerburgh
Copy link
Member

I'm happy to merge as it is

@Austio
Copy link
Contributor Author

Austio commented Nov 6, 2017

Cool let's go ahead and merge and if we need the central in future can add then.

@Austio
Copy link
Contributor Author

Austio commented Nov 9, 2017

@eddyerburgh hey hey, wanted to ping you on this one, good to merge when you are ☮️

@eddyerburgh eddyerburgh merged commit 3f3c64a into vuejs:dev Nov 9, 2017
@eddyerburgh
Copy link
Member

The tests are failing on my machine for some reason. The custom error is thrown, but it doesn't propagate 🤔

I'm going to skip them for the moment and have a look later, but do you have any idea why that might be?

@Austio
Copy link
Contributor Author

Austio commented Nov 11, 2017

Hey nothing off top of head. Any specific reproduction steps? Should be able to gander here in a few hours.

@Austio
Copy link
Contributor Author

Austio commented Nov 11, 2017

@eddyerburgh patched #170

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

Successfully merging this pull request may close these issues.

Expected Behavior of Error Propogation
2 participants