Skip to content

Commit c863520

Browse files
committed
fix: prevent setProps infinite loop with immediate watchers
* prevent `setProps` from being called on non-top level wrappers * remove useless `silent` option from config
1 parent d2add54 commit c863520

File tree

18 files changed

+120
-178
lines changed

18 files changed

+120
-178
lines changed

docs/api/config.md

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ config.deprecationWarningHandler = (method, message) => {
4747
- type: `{ [name: string]: Component | boolean | string }`
4848
- default: `{}`
4949

50-
The stub stored in `config.stubs` is used by default.
50+
The stub stored in `config.stubs` is used by default.
5151
Stubs to use in components. These are overwritten by `stubs` passed in the mounting options.
5252

5353
When passing `stubs` as an array in the mounting options, `config.stubs` are converted to an array, and will stub components with a basic component that returns `<${component name}-stub>`.
@@ -112,18 +112,3 @@ config.provide['$logger'] = {
112112
}
113113
}
114114
```
115-
116-
### `silent`
117-
118-
- type: `Boolean`
119-
- default: `true`
120-
121-
It suppresses warnings triggered by Vue while mutating component's observables (e.g. props). When set to `false`, all warnings are visible in the console. This is a configurable way which relies on `Vue.config.silent`.
122-
123-
Example:
124-
125-
```js
126-
import { config } from '@vue/test-utils'
127-
128-
config.silent = false
129-
```

docs/api/wrapper/setProps.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88

99
Sets `Wrapper` `vm` props and forces update.
1010

11-
**Note the Wrapper must contain a Vue instance.**
11+
::: warning
12+
`setProps` could be called only for top-level component, mounted by `mount` or `shallowMount`
13+
:::
1214

1315
```js
1416
import { mount } from '@vue/test-utils'

docs/ja/api/config.md

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,3 @@ config.provide['$logger'] = {
7373
}
7474
}
7575
```
76-
77-
### `silent`
78-
79-
- 型: `Boolean`
80-
- デフォルト: `true`
81-
82-
Vue がコンポーネントの変更を感知するプロパティ(例えば props )が変更される時に出す警告を出力しません。`false` をセットするとすべての警告はコンソールに表示されません。この機能は `Vue.config.silent` を使って実現しています。
83-
84-
例:
85-
86-
```js
87-
import { config } from '@vue/test-utils'
88-
89-
config.silent = false
90-
```

docs/ru/api/config.md

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,3 @@ config.provide['$logger'] = {
7474
}
7575
}
7676
```
77-
78-
### `silent`
79-
80-
- Тип: `Boolean`
81-
- По умолчанию: `true`
82-
83-
Подавляет предупреждения, вызванные Vue во время изменения наблюдаемых компонентов (например, входных параметров). Если установлено значение `false`, все предупреждения показываются в консоли. Это настраиваемый способ, который основывается на `Vue.config.silent`.
84-
85-
Пример:
86-
87-
```js
88-
import { config } from '@vue/test-utils'
89-
90-
config.silent = false
91-
```

docs/ru/api/wrapper/setProps.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88

99
Устанавливает входные параметры `Wrapper` `vm` и выполняет принудительное обновление.
1010

11-
**Обратите внимание, что `Wrapper` должен содержать экземпляр Vue.**
11+
::: warning Обратите внимание!
12+
`setProps` может быть вызван только на `wrapper` верхнего уровня, который был создан с помощью `mount` или `shallowMount`
13+
:::
1214

1315
```js
1416
import { mount } from '@vue/test-utils'

docs/zh/api/config.md

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ config.showDeprecationWarnings = false
2424
- 类型:`{ [name: string]: Component | boolean | string }`
2525
- 默认值:`{}`
2626

27-
存储在 `config.stubs` 中的存根会被默认使用。
27+
存储在 `config.stubs` 中的存根会被默认使用。
2828
用到的组件存根。它们会被传入挂载选项的 `stubs` 覆写。
2929

3030
当把 `stubs` 作为一个数组传入挂载选项时,`config.stubs` 会被转换为一个数组,然后用只返回一个 `<${component name}-stub>` 的基础组件进行存根。
@@ -89,18 +89,3 @@ config.provide['$logger'] = {
8989
}
9090
}
9191
```
92-
93-
### `silent`
94-
95-
- 类型:`Boolean`
96-
- 默认值:`true`
97-
98-
在组件的可观察内容 (如 props) 发生突变时,警告会被 Vue 阻止。当设置为 `false` 时,所有的警告都会出现在控制台中。这是一个 `Vue.config.silent` 的配置方式。
99-
100-
示例;
101-
102-
```js
103-
import { config } from '@vue/test-utils'
104-
105-
config.silent = false
106-
```

flow/config.flow.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@ declare type Config = {
33
mocks?: Object,
44
methods?: { [name: string]: Function },
55
provide?: Object,
6-
silent?: boolean,
76
showDeprecationWarnings?: boolean
87
}

packages/create-instance/create-instance.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import createScopedSlots from './create-scoped-slots'
1111
import { createStubsFromStubsObject } from './create-component-stubs'
1212
import { patchCreateElement } from './patch-create-element'
1313

14-
function createContext(options, scopedSlots) {
14+
function createContext(options, scopedSlots, currentProps) {
1515
const on = {
1616
...(options.context && options.context.on),
1717
...options.listeners
@@ -20,8 +20,8 @@ function createContext(options, scopedSlots) {
2020
attrs: {
2121
...options.attrs,
2222
// pass as attrs so that inheritAttrs works correctly
23-
// propsData should take precedence over attrs
24-
...options.propsData
23+
// props should take precedence over attrs
24+
...currentProps
2525
},
2626
...(options.context || {}),
2727
on,
@@ -110,16 +110,26 @@ export default function createInstance(
110110
parentComponentOptions.provide = function() {
111111
return {
112112
...getValuesFromCallableOption.call(this, originalParentComponentProvide),
113+
// $FlowIgnore
113114
...getValuesFromCallableOption.call(this, options.provide)
114115
}
115116
}
116117

118+
const originalParentComponentData = parentComponentOptions.data
119+
parentComponentOptions.data = function() {
120+
return {
121+
...getValuesFromCallableOption.call(this, originalParentComponentData),
122+
vueTestUtils_childProps: { ...options.propsData }
123+
}
124+
}
125+
117126
parentComponentOptions.$_doNotStubChildren = true
127+
parentComponentOptions.$_isWrapperParent = true
118128
parentComponentOptions._isFunctionalContainer = componentOptions.functional
119129
parentComponentOptions.render = function(h) {
120130
return h(
121131
Constructor,
122-
createContext(options, scopedSlots),
132+
createContext(options, scopedSlots, this.vueTestUtils_childProps),
123133
createChildren(this, h, options)
124134
)
125135
}

packages/server-test-utils/types/index.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ interface VueTestUtilsConfigOptions {
4545
mocks?: object
4646
methods?: Record<string, Function>
4747
provide?: object,
48-
silent?: Boolean
4948
}
5049

5150
export declare let config: VueTestUtilsConfigOptions

packages/server-test-utils/types/test/renderToString.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,3 @@ config.methods = {
6666
config.provide = {
6767
foo: {}
6868
}
69-
config.silent = true

0 commit comments

Comments
 (0)