-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
Add warnHandler to allow users to set a custom warn callback #5883
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
Conversation
If this feature is wanted, I will, of course, open a PR for the API docs. |
|
||
warn(msg, vm) | ||
|
||
expect(msg).toHaveBeenWarned() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
toHaveBeenWarned
currently still regards something being "warned" when it calls console.error
(warnHandler
is not set). Did we want to change this so it also tracks if a custom warnHandler has been called?
|
||
warn(msg, vm) | ||
|
||
expect(Vue.config.warnHandler).toHaveBeenCalledWith(msg, vm, jasmine.any(String)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you can see here, I don't explicitly match the trace
argument as I cannot spy the generateComponentTrace
method without exporting it and wanted to avoid that without approval from a maintainer.
Added a jsfiddle example in the description. Sorry it's so slow, didn't want to upload my dist file so just pasted it inline. 😬 |
Thanks - this is great! I can also imagine some creative use cases during development (e.g. warning overlays) |
Thanks @yyx990803! |
Similar to errorHandler, but for warnings. https://vuejs.org/v2/api/#errorHandler
Sorry for not following the "Ideally you should open a suggestion issue first and have it greenlighted before working on it." rule, no loss on my side if you don't want to accept this.
I would like this feature as it will allow Vue to call a user provided callback for
warn
ings which helps for asserting the state of warnings during testing or development, without having to either spyon or monkeypatch theconsole.error
function.What kind of change does this PR introduce? (check at least one)
Does this PR introduce a breaking change? (check one)
If yes, please describe the impact and migration path for existing applications:
The PR fulfills these requirements:
dev
branch for v2.x (or to a previous version branch), not themaster
branchfix #xxx[,#xxx]
, where "xxx" is the issue number)If adding a new feature, the PR's description includes:
(sorry!)
Other information:
jsfiddle example: https://jsfiddle.net/vx0ks9yo/3/