-
Notifications
You must be signed in to change notification settings - Fork 668
New type definitions for TypeScript are missed #1529
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
Comments
Oops. We should add those definitions. |
I can fix this later today. 🤦 and do 1.0.1 straight away. Or if you have time before me you can send a PR and I can get it merged up. |
Can someone please review? #1530 |
Also I believe the new |
@jmariller yep, I fixed that too. It should be fixed now: https://www.npmjs.com/package/@vue/test-utils 1.0.1 is out. LMK if I missed anything. |
@lmiller1990 thanks a lot for the quick fix & feedback! I shortly checked and it seems something is still missing in the definitions for |
I am new to TS, I probably messed up. I will fix it right now. Funny how no-one noticed bugs until 1.0 drops ): |
Ok.... try getting 1.0.2 and see if that fixed it for you. Thanks! If not, lmk and I'll look into it. |
Works now! Thank you so much @lmiller1990 for the quick fix, really appreciate it! And thanks in general for these utils, they are great :) |
@lmiller1990 Now I see deprecations about |
@Ky6uk hi! We removed |
@afontcu the test is very simple. I'm trying to |
Try using jest.spyOn |
@dobromir-hristov on what property? It doesn't seem easy to avoid deprecation atm. The most convenient way regarding documentation to check a method without firing the implementation is to use it('triggers click', () => {
const mock = jest.fn();
const wrapper = shallowMount(Component);
wrapper.setMethods({ onClick: mock });
const linkWrapper = wrapper.findComponent({ name: 'Link' });
expect(mock).toBeCalledTimes(0);
linkWrapper.vm.$emit('click');
expect(mock).toBeCalledTimes(1);
}); |
So instead of checking whether your logic is correct and the right event is emitted or dom is changed from that click action, you just want to see if you are listening to it properly? Then write another separate test to actually test your logic? Isn't that double the work? |
It just an example. The test itself may check that the emits will call the correct methods. For example, one click will call this method, double click will call another method, or the same method with a different argument, etc. And I shouldn't think about the implementation of the methods because of the logic inside too complicated and tested by different unit tests. That the idea. It's not double work, it's separating tests for complicated logic aside component tests. |
Hm what about |
It doesn't work. |
I'd say the component calling a method on an event is precisely an implementation detail, isn't it? The side-effects of this method (HTTP requests, cookies, other emitted events…) are the visible part of the interaction, and the one I'd test. Can you provide a reproduction link (codesandbox or similar)? Happy to help. |
@afontcu component can not be changed after an interaction. It can just trigger another logic under the hood. And my case is to be sure all triggers are calling the right methods in the component. That's it. I have not used codesandbox before, I will check it's possible to add a quick test for that. Upd: I've tried to create a sandbox, but it doesn't seem to work. |
In this (contrived, of course!) example, I'd say that the interesting behaviour from the outside is that the component logs something after a click. For that, using a method or simply calling In that test, I would suggest mocking/spying console.log, and assert it's been called right after triggering a click. |
Yes, It makes sense. But it will also require to rewrite a bunch of tests before upgrading to vtu 2.0. The mocking methods directly still look useful in some cases to not remove them completely. Anyway, thanks to clarify. |
I was led here from this thread: #1536 Unfortunately, not being able to use the In my particular case, I have a component that during created calls a method recursively. In my tests, I was able to resolve this issue my making use of the methods option:
I'm not sure how to proceed without the ability to override it for any of my mounted tests. |
Hi @robokozo! That sounds interesting. Could you share a reproduction link or a repository to take a look at this use case? |
@afontcu No I can't... how embarrassing ^^ I can't reproduce it in an isolated environment because of a bug in the original code I was referring to. It looks good! Keep it up the great work! (The vue testing team should consider opening themselves up for github sponsorships) |
One immediately work around that comes to mind (maybe not ideal) would be to put said method in another file and import it. Then you could use
To do this, the variable passed into Maybe not ideal, but I think the situation you describe is one of the few edge cases where there is no direct migration path. When you provide a minimal example, maybe we can find another option. |
I have functions to render correct data used like this:
convertServerZoneToUserZone function is from mixin. But i don't need to test it in component. Register it as jest.fn() was fast and useful. How to mock this function? Without mocking it i can not to render component and test it. |
If it is from a mixin, you are doing jest.mock('./some-mixin', () => ({
convertServerZoneToUserZone: () => {}
})) |
@lmiller1990 I was trying like that
and then i got error: I add mixin to shallowMount, try 'mount' also, but it changes nothing |
Assuming that mixins is a method you probably need to do:
|
@lmiller1990 🤦 of course it works now. Sometimes i feel so stupid ;) Thanks! But i have another problem. I have button. After click it runs function. And that function runs another function. But this last function is from plugin. So i should spy on first function, and then mock function from plugin. But if i do that like this:
Vue stops working because of lack of Vue.use() summary: Buttons runs funcion a(). Function a runs function b(), and function b runs toasted which i cant mock. How to handle that? |
Please share the function that runs the plugin code |
And the problem is this.$toasted.error(). If i mock vue module like
This function is mocked. But i had errors like Vue.use is not a function etc. I broke whole instance then i think. But otherwise mocking many functions only for check if button runs function a() is not good in my opinion. Register function is fast end easy. I really don't understand why i cant use it. |
This is not how jest.mock works. You cannot "partially" mock something like this - you either mock the entire module, or you don't. Can you use
|
Version
1.0.0
It looks
index.d.ts
isn't updated yet. After upgrading tov1.0.0
I started to get deprecation errors, but methods likefindAllComponents
andfindComponent
are missed inindex.d.ts
.The text was updated successfully, but these errors were encountered: