Skip to content

fix #1541: Improve deprecation messages #1548

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 7 commits into from
May 17, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
2 changes: 1 addition & 1 deletion docs/api/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ wrapper.destroy()
- type: `boolean`
- default: `false`

::: warning
::: warning Deprecation warning
`attachToDocument` is deprecated and will be removed in future releases. Use [`attachTo`](#attachto) instead.
:::

Expand Down
2 changes: 1 addition & 1 deletion docs/api/wrapper-array/isEmpty.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## isEmpty

::: warning
::: warning Deprecation warning
`isEmpty` is deprecated and will be removed in future releases.

Consider a custom matcher such as those provided in [jest-dom](https://github.com/testing-library/jest-dom#tobeempty).
Expand Down
6 changes: 5 additions & 1 deletion docs/api/wrapper-array/isVueInstance.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
## isVueInstance

::: warning
::: warning Deprecation warning
`isVueInstance` is deprecated and will be removed in future releases.

Most of the times, tests relying on `isVueInstance` provide little to no-value so you could simply remove them.

If you want to keep these tests, a valid replacement is to assert that `wrapper.find(...).vm` exists.
:::

Assert every `Wrapper` in `WrapperArray` is Vue instance.
Expand Down
6 changes: 5 additions & 1 deletion docs/api/wrapper-array/setMethods.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
## setMethods

::: warning
::: warning Deprecation warning
`setMethods` is deprecated and will be removed in future releases.

There's no clear path to replace `setMethods`, because it really depends on your previous usage. It easily leads to flaky tests that rely on implementation details, which [is discouraged](https://github.com/vuejs/rfcs/blob/668866fa71d70322f6a7689e88554ab27d349f9c/active-rfcs/0000-vtu-api.md#setmethods).

Thus, we suggest to to rethink those tests using the tools Vue Test Utils provides.
:::

Sets `Wrapper` `vm` methods and forces update on each `Wrapper` in `WrapperArray`.
Expand Down
2 changes: 1 addition & 1 deletion docs/api/wrapper/emittedByOrder.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## emittedByOrder

::: warning
::: warning Deprecation warning
`emittedByOrder` is deprecated and will be removed in future releases.

Use `wrapper.emitted` instead.
Expand Down
2 changes: 1 addition & 1 deletion docs/api/wrapper/find.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## find

::: warning
::: warning Deprecation warning
Using `find` to search for a Component is deprecated and will be removed. Use `findComponent` instead.
:::

Expand Down
2 changes: 1 addition & 1 deletion docs/api/wrapper/findAll.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## findAll

::: warning
::: warning Deprecation warning
Using `findAll` to search for Components is deprecated and will be removed. Use `findAllComponents` instead.
:::

Expand Down
2 changes: 1 addition & 1 deletion docs/api/wrapper/isEmpty.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## isEmpty

::: warning
::: warning Deprecation warning
`isEmpty` is deprecated and will be removed in future releases.

Consider a custom matcher such as those provided in [jest-dom](https://github.com/testing-library/jest-dom#tobeempty).
Expand Down
2 changes: 1 addition & 1 deletion docs/api/wrapper/isVisible.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## isVisible

::: warning
::: warning Deprecation warning
`isVisible` is deprecated and will be removed in future releases.

Consider a custom matcher such as those provided in [jest-dom](https://github.com/testing-library/jest-dom#tobevisible).
Expand Down
6 changes: 5 additions & 1 deletion docs/api/wrapper/isVueInstance.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
## isVueInstance

::: warning
::: warning Deprecation warning
`isVueInstance` is deprecated and will be removed in future releases.

Most of the times, tests relying on `isVueInstance` provide little to no-value so you could simply remove them.

If you want to keep these tests, a valid replacement is to assert that `wrapper.find(...).vm` exists.
:::

Assert `Wrapper` is Vue instance.
Expand Down
2 changes: 1 addition & 1 deletion docs/api/wrapper/name.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## name

::: warning
::: warning Deprecation warning
`name` is deprecated and will be removed in future releases.
:::

Expand Down
2 changes: 1 addition & 1 deletion docs/api/wrapper/overview.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## overview

::: warning
::: warning Deprecation warning
`overview` is deprecated and will be removed in future releases.
:::

Expand Down
6 changes: 5 additions & 1 deletion docs/api/wrapper/setMethods.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
## setMethods

::: warning
::: warning Deprecation warning
`setMethods` is deprecated and will be removed in future releases.

There's no clear path to replace `setMethods`, because it really depends on your previous usage. It easily leads to flaky tests that rely on implementation details, which [is discouraged](https://github.com/vuejs/rfcs/blob/668866fa71d70322f6a7689e88554ab27d349f9c/active-rfcs/0000-vtu-api.md#setmethods).

Thus, we suggest to to rethink those tests using the tools Vue Test Utils provides.
:::

Sets `Wrapper` `vm` methods and forces update.
Expand Down
5 changes: 4 additions & 1 deletion packages/shared/merge-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ export function mergeOptions(
[key: string]: Function
})
if (methods && Object.keys(methods).length) {
warnDeprecated('overwriting methods via the `methods` property')
warnDeprecated(
'overwriting methods via the `methods` property',
'There is no clear migration path for the `methods` property - Vue does not support arbitrarily replacement of methods, nor should VTU. If you need to stub out a method, extract it out and test it. Otherwise, the suggestion is to rethink those tests'
)
}

const provide = (getOption(options.provide, config.provide): Object)
Expand Down
5 changes: 4 additions & 1 deletion packages/test-utils/src/wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,10 @@ export default class Wrapper implements BaseWrapper {
* @deprecated
*/
setMethods(methods: Object): void {
warnDeprecated(`setMethods`)
warnDeprecated(
`setMethods`,
`There is no clear migration path for setMethods - Vue does not support arbitrarily replacement of methods, nor should VTU. If you need to stub out a method, extract it out and test it. Otherwise, the suggestion is to rethink those tests`
)

if (!this.vm) {
throwError(`wrapper.setMethods() can only be called on a Vue instance`)
Expand Down
54 changes: 54 additions & 0 deletions test/specs/config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,58 @@ describeWithShallowAndMount('config', mountingMethod => {
)
})
})

describe('methods overriding deprecation warning', () => {
const expectedErrorMessage = `There is no clear migration path`
const Component = {
template: '<div></div>',
methods: {
foo() {}
}
}

it('should show warning for options.methods if config is enabled', () => {
config.showDeprecationWarnings = true

mountingMethod(Component, {
methods: { foo: () => {} }
})

expect(console.error).to.be.calledWith(
sandbox.match(expectedErrorMessage)
)
})

it('should not show warning for options.methods if config is disabled', () => {
config.showDeprecationWarnings = false

mountingMethod(Component, {
methods: { foo: () => {} }
})

expect(console.error).not.to.be.calledWith(
sandbox.match(expectedErrorMessage)
)
})

it('should show warning for setMethods if config is enabled', () => {
config.showDeprecationWarnings = true

mountingMethod(Component).setMethods({ foo: () => {} })

expect(console.error).to.be.calledWith(
sandbox.match(expectedErrorMessage)
)
})

it('should not show warning for setMethods if config is disabled', () => {
config.showDeprecationWarnings = false

mountingMethod(Component).setMethods({ foo: () => {} })

expect(console.error).not.to.be.calledWith(
sandbox.match(expectedErrorMessage)
)
})
})
})