8000 createLocalVue errorHandler Option by AtofStryker · Pull Request #1670 · vuejs/vue-test-utils · GitHub
[go: up one dir, main page]

Skip to content
8000

createLocalVue errorHandler Option #1670

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
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
48f1c14
refactor(createlocalvue): move createLocalVue to shared utils
AtofStryker Aug 26, 2020
808fe89
refactor(createlocalvue): rename createLocalVue to _createLocalVue
AtofStryker Aug 26, 2020
98103d6
improvement(components): add Sync and Async components for testing
AtofStryker Aug 27, 2020
fc3be6c
improvement(flow): add VueConfig to Flow
AtofStryker Aug 27, 2020
0dca580
improvement(index): export new createLocalVue as default in Index
AtofStryker Aug 27, 2020
094e7db
improvement(_createlocalvue): allow registration of user defined config
AtofStryker Aug 27, 2020
3db2482
improvement(find): add findAllParentInstances to the find API
AtofStryker Aug 27, 2020
f1005a9
improvement(mount): pass localVue into mounted createLocalVue
AtofStryker Aug 27, 2020
72f1fdb
improvement(error): call user defined errorHandler if defined
AtofStryker Aug 27, 2020
55647c4
improvement(createlocalvue): add tests to createLocalVue errorHandler
AtofStryker Aug 27, 2020
8bbc3d1
docs(createlocalvue): document public createLocalVue API
AtofStryker Aug 28, 2020
75d0afc
docs(createlocalvue): document the createLocalVue internal API
AtofStryker Aug 28, 2020
ba9f677
docs(createlocalvue): document the errorHandler option in createLocalVue
AtofStryker Aug 28, 2020
3272a85
fix(createlocalvue tests): wrap createLocalVue async test in try/finally
AtofStryker Aug 28, 2020
5783bb6
fix(createlocalvue): skip async component throws for vue < 2.6
AtofStryker Aug 28, 2020 8000
5ed0f28
improvement(find and error): add additional type safety to find & error
AtofStryker Aug 28, 2020
d73e8d9
fix(createlocalvue): only run sync error tests for vue versions < 2.4
AtofStryker Aug 28, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
docs(createlocalvue): document the errorHandler option in createLocalVue
  • Loading branch information
AtofStryker committed Aug 28, 2020
commit ba9f6777e4159f7bc5e7f35502371863fe3621fc
29 changes: 29 additions & 0 deletions docs/api/createLocalVue.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## createLocalVue()

- **Arguments:**

- `{Object} options`
- `{Function} errorHandler`

- **Returns:**

- `{Component}`
Expand All @@ -8,8 +13,12 @@

`createLocalVue` returns a Vue class for you to add components, mixins and install plugins without polluting the global Vue class.

The `errorHandler` option can be used to handle uncaught errors during component render function and watchers.

Use it with `options.localVue`:

**Without options:**

```js
import { createLocalVue, shallowMount } from '@vue/test-utils'
import MyPlugin from 'my-plugin'
Expand All @@ -27,4 +36,24 @@ const freshWrapper = shallowMount(Foo)
expect(freshWrapper.vm.foo).toBe(false)
```

**With the [`errorHandler`](https://vuejs.org/v2/api/#errorHandler) option:**

```js
import { createLocalVue, shallowMount } from '@vue/test-utils'
import Foo from './Foo.vue'

const errorHandler = (err, vm, info) => {
expect(err).toBeInstanceOf(Error)
}

const localVue = createLocalVue({
errorHandler
})

// Foo throws an error inside a lifecycle hook
const wrapper = shallowMount(Foo, {
localVue
})
```

- **See also:** [Common Tips](../guides/common-tips.md#applying-global-plugins-and-mixins)
29 changes: 29 additions & 0 deletions docs/ja/api/createLocalVue.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## createLocalVue()

- **引数:**

- `{Object} options`
- `{Function} errorHandler`

- **戻り値:**

- `{Component}`
Expand All @@ -8,8 +13,12 @@

`createLocalVue` は、グローバル Vue クラスを汚染することなくコンポーネント、ミックスイン、プラグインを追加するための Vue クラスを返します。

[errorHandler](https://jp.vuejs.org/v2/api/index.html#errorHandler)オプションを使用すると、コンポーネントのレンダー機能とウォッチャー中にキャッチされなかったエラーを処理できます。

`options.localVue` と一緒に使用してください。

**オプションなし:**

```js
import { createLocalVue, shallowMount } from '@vue/test-utils'
import Foo from './Foo.vue'
Expand All @@ -25,4 +34,24 @@ const freshWrapper = shallowMount(Foo)
expect(freshWrapper.vm.foo).toBe(false)
```

**[errorHandler](https://jp.vuejs.org/v2/api/index.html#errorHandler)オプションを使用:**

```js
import { createLocalVue, shallowMount } from '@vue/test-utils'
import Foo from './Foo.vue'

const errorHandler = (err, vm, info) => {
expect(err).toBeInstanceOf(Error)
}

const localVue = createLocalVue({
errorHandler
})

// Fooがライフサイクルフック内でエラーをスローする
const wrapper = shallowMount(Foo, {
localVue
})
```

- **参照:** [一般的なヒント](../guides/common-tips.md#グローバルプラグインとミックスインの適用)
29 changes: 29 additions & 0 deletions docs/ru/api/createLocalVue.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## createLocalVue()

- **Аргументы:**

- `{Object} options`
- `{Function} errorHandler`

- **Возвращает:**

- `{Component}`
Expand All @@ -8,8 +13,12 @@

`createLocalVue` возвращает класс Vue, чтобы вы могли добавлять компоненты, примеси и устанавливать плагины без загрязнения глобального класса Vue.

Опция [errorHandler](https://ru.vuejs.org/v2/api/index.html#errorHandler) может использоваться для обработки неперехваченных ошибок во время функции визуализации компонента и наблюдателей.

Используйте вместе с `options.localVue`:

**Без опций:**

```js
import { createLocalVue, shallowMount } from '@vue/test-utils'
import Foo from './Foo.vue'
Expand All @@ -25,4 +34,24 @@ const freshWrapper = shallowMount(Foo)
expect(freshWrapper.vm.foo).toBe(false)
```

**С опцией [errorHandler](https://ru.vuejs.org/v2/api/index.html#errorHandler):**

```js
import { createLocalVue, shallowMount } from '@vue/test-utils'
import Foo from './Foo.vue'

const errorHandler = (err, vm, info) => {
expect(err).toBeInstanceOf(Error)
}

const localVue = createLocalVue({
errorHandler
})

// Foo выдает ошибку внутри ловушки жизненного цикла
const wrapper = shallowMount(Foo, {
localVue
})
```

- **См. также:** [Общие советы](../guides/common-tips.md#добавnение-гnобаnьных-пnагинов-и-примесей)
29 changes: 29 additions & 0 deletions docs/zh/api/createLocalVue.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## createLocalVue()

- **参数:**

- `{Object} options`
- `{Function} errorHandler`

- **返回值:**

- `{Component}`
Expand All @@ -8,8 +13,12 @@

`createLocalVue` 返回一个 Vue 的类供你添加组件、混入和安装插件而不会污染全局的 Vue 类。

在组件渲染功能和观察者期间,[`errorHandler`](https://cn.vuejs.org/v2/api/index.html#errorHandler)选项可用于处理未捕获的错误。

可通过 `options.localVue` 来使用:

**Without options:**

```js
import { createLocalVue, shallowMount } from '@vue/test-utils'
import MyPlugin from 'my-plugin'
Expand All @@ -27,4 +36,24 @@ const freshWrapper = shallowMount(Foo)
expect(freshWrapper.vm.foo).toBe(false)
```

**使用[`errorHandler`](https://cn.vuejs.org/v2/api/index.html#errorHandler)选项:**

```js
import { createLocalVue, shallowMount } from '@vue/test-utils'
import Foo from './Foo.vue'

const errorHandler = (err, vm, info) => {
expect(err).toBeInstanceOf(Error)
}

const localVue = createLocalVue({
errorHandler
})

// Foo在生命周期挂钩中引发错误
const wrapper = shallowMount(Foo, {
localVue
})
```

- **延伸阅读:**[常用技巧](../guides/common-tips.md#applying-global-plugins-and-mixins)
0