-
Notifications
You must be signed in to change notification settings - Fork 668
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
Explain what the replacement for deprecations are #1541
Comments
Hi! Thanks for filling this in. There's no clear path to replace Still, if you have some ideas of guidance/suggestions to help users, we'll be more than happy to review a PR! 😃 |
For isVueInstance , if the note included at https://github.com/dobromir-hristov/rfcs/blob/vtu-2-api/active-rfcs/0000-vtu-api.md#isvueinstance
were added it would have saved me a little time finding this as well (ie to use findComponent ) |
Would be awesome if this is reflected in the deprecation warning. Maybe link to that page. Right now we get 100's of deprecation warnings without a clear path on how to fix them. |
Makes sense, thank you all for the suggestion. Anyone fancy to open up a PR with improved deprecation messages? 😇 otherwise I will. cheers! |
I have the similar problem with Now that I have the deprecation notice, I do not know how I can replace this basic test. Any idea ? Thanks a lot! |
Nevermind, looks like |
I'm just plus one-ing the need to explain what to use to replace |
For You could do
If anyone has a complicated test with If the deprecations messages are super annoying, you can temporarily silence them: import { config } from `@vue/test-utils`
config.showDeprecationWarnings = false |
Hi folks! I'm pinging everyone on this issue because #1548 is up and we'd like to receive your feedback on the updated deprecation messages 😇 thanks! |
* docs: improve title on deprecation warnings * docs: add suggestion for isVueInstance * refactor: improve migration path for setMethods and options.methods * docs: fix link format * docs: add more hints to replace setMethods and options.methods * docs: reword messages * docs: remove implicit statement
@afontcu |
@lmiller1990
How come it is testing an implementation detail ? I do not see that, if you can explain, thank you |
Ideally you should test the input and output of the component (or any function in general, when writing tests). For example, for a Vue component, the inputs might be a user filling out a form and submitting it, and the output might be the component renders a "Success" message. We don't really care how the component works, but that the behavior is correct. Asserting that something is a Vue instance is not very useful and provides little value; it's much better practice to test the behavior. |
I agree with the behavioral testing, you explained that very well and many times on your website. However, IMHO, I like to use |
Given that scenario, wouldn't any other test against that Component fail, too? |
Its a smoke test. If that test is failing you know something major with the component off. When I have a whole slew of errors I've found it is easier to look for the most simple test that failed, fix that then continue up in complexity. Basically the single responsibility principle for tests. |
In that (legit!) case, you might want to use |
Sorry I dont get what should we put in the
|
whatever you were doing in the first place. for example, from: expect(wrapper.findComponent(myComponent)).isVueInstance() to expect(wrapper.findComponent(myComponent).vm).toBeTruthy() |
@afontcu import Component from '@/components/ComponentName'
beforeEach(() => {
wrapper = shallowMount(Component, {
i18n,
store,
localVue,
router
})
vm = wrapper.vm
})
test('is a Vue instance', () => {
expect(wrapper.isVueInstance()).toBeTruthy()
}) what should I do if I want to do the same smoke test? |
|
noted, i probably wont use this in my personal project but it's work project and we have lots of
thanks for the suggestion @lmiller1990 👍 |
methods property is deprecated and will be removed (see : vuejs/vue-test-utils#1541) + some refactoring because of warnings in unit tests
@afontcu there is a place i think this is usable, especially in the created hook, to test if a method is called on component create hook . here is a sample of what I have. Since getBanks is an external call, i need to replace it's implementation import SendToBank from "../SendToBank";
|
@ogomaemmanuel would you not just mock out the API lib (eg axios) and assert that was called? |
That throws a deprecated warning though. How to do the same thing without getting a warning? |
@lmiller1990 that one will work for external api's, but sometime you just want some functions to be called when a the component is created, I have been in situations where I either forget to put a function in the created hook or by accident the functions get removed. To ensure these functions aren't interfered with, I need to pass a mock that will be called during component creation |
I'm sorry, but |
I've solved it by inserting functions after the mounting completed. const wrapper = shallowMount(Component)
wrapper.vm.methodToBeMocked = jest.fn(); |
@lmiller1990 I have gotten how to go about it, just mocking the function before calling mount |
@keremistan thanks for your share! const created = function () {
this.apiGetProducts();
}; old test code: shallowMount(component, {
localVue,
methods: {
apiGetProducts,
},
});
/** assert */
expect(apiGetProducts).toBeCalledTimes(1); Warning was throw because How can I solve it? |
What does The idea is to discourage these kind of tests - your tests is not very useful, if you were to delete the |
not completely API call. const created = function () {
this.apiGetProducts();
};
const methods = {
apiGetProducts() {
getProduct().then(res => {
... do Something
})
.... more then
},
} |
What is |
Thanks for you answer 👍 I has solved this question. test('[Main] `created` execute `apiGetProducts`、`apiGetWishListStatus` methods. ', () => {
/** arrange */
const apiGetProducts = jest.fn();
const apiGetWishListStatus = jest.fn();
// mock methods
localMixin.methods = { ...mixin.methods, apiGetProducts, apiGetWishListStatus };
/** act */
shallowMount(component, {
localVue,
... abort
});
/** assert */
expect(apiGetProducts).toBeCalledTimes(1);
expect(apiGetWishListStatus).toBeCalledTimes(1);
}); |
I solved my problem with this method |
What problem does this feature solve?
The documentation for for example setMethods is unclear. It simply states: "setMethods is deprecated and will be removed in future releases.". Same goes for isVueInstance.
This does not explain what the replacement (if any) should be, or why this was deprecated.
These types of warnings also happens when running the tests:
"[vue-test-utils]: overwriting methods via the
methods
property is deprecated and will removed in the next major version"Here it's also unclear what the fix should be or why this was deprecated.
What does the proposed API look like?
Not applicable.
The text was updated successfully, but these errors were encountered: