-
Notifications
You must be signed in to change notification settings - Fork 668
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: handle errors in destroy (#1106)
- Loading branch information
1 parent
d2f26e8
commit efab983
Showing
11 changed files
with
107 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { warn } from 'shared/util' | ||
import { findAllInstances } from './find' | ||
|
||
function errorHandler (errorOrString, vm) { | ||
const error = | ||
typeof errorOrString === 'object' | ||
? errorOrString | ||
: new Error(errorOrString) | ||
|
||
vm._error = error | ||
throw error | ||
} | ||
|
||
export function throwIfInstancesThrew (vm) { | ||
const instancesWithError = findAllInstances(vm).filter( | ||
_vm => _vm._error | ||
) | ||
|
||
if (instancesWithError.length > 0) { | ||
throw instancesWithError[0]._error | ||
} | ||
} | ||
|
||
let hasWarned = false | ||
|
||
// Vue swallows errors thrown by instances, even if the global error handler | ||
// throws. In order to throw in the test, we add an _error property to an | ||
// instance when it throws. Then we loop through the instances with | ||
// throwIfInstancesThrew and throw an error in the test context if any | ||
// instances threw. | ||
export function addGlobalErrorHandler (_Vue) { | ||
const existingErrorHandler = _Vue.config.errorHandler | ||
|
||
if (existingErrorHandler === errorHandler) { | ||
return | ||
} | ||
|
||
if (_Vue.config.errorHandler && !hasWarned) { | ||
warn( | ||
`Global error handler detected (Vue.config.errorHandler). \n` + | ||
`Vue Test Utils sets a custom error handler to throw errors ` + | ||
`thrown by instances. If you want this behavior in ` + | ||
`your tests, you must remove the global error handler.` | ||
) | ||
hasWarned = true | ||
} else { | ||
_Vue.config.errorHandler = errorHandler | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters