-
Notifications
You must be signed in to change notification settings - Fork 669
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
add section to docs on testing components that include promises #151
Comments
trigger
on methods that return promisestriggerAsync
method for tests that use promises
triggerAsync
method for tests that use promisestrigger
methods that call methods using promises
We could add an
I've been using a library called flush-promises. You can write nice tests in Jest with async/ await that stops you adding setTimeouts inside the tests.
You can see an example here — https://github.com/eddyerburgh/vue-hackernews-chapter-6/blob/master/src/store/__tests__/actions.spec.js#L28 |
Flush promises looks like it might do nicely. Will try integrate it and see if it solves my problem, and report back. Have you felt the need or are you happy with just using |
Testing the vee-validate example, EDIT: It appears to be working now after fixing an issue with babel. It would definitely be nicer to have a built in method for handling Promises though. |
I don't think vue-test-utils should have a built in way to deal with promises. It's not vue specific, and there are already libraries that flush promises. It's up for discussion, but my opinion is we should use other libraries for it. Instead we could add a section to the docs. |
There should definitely be a section in the docs, especially since plugins like vee-validate, which uses Promises quite heavily, are popular. |
trigger
methods that call methods using promises
@lmiller1990 I changed the title to add a section to the docs, if your original issue wasn't solved we can revert the name. |
Slightly off-topic seeing what was discussed above, but since this is now a docs issue on this subject, I'll comment here. The docs imply (https://vue-test-utils.vuejs.org/en/guides/getting-started.html#what-about-nexttick) that we don't have to worry about component refreshes, but it seems that things like Example:
|
You need to use |
Useful pointers, thanks @eddyerburgh |
First, I am not sure if this is something vue-test-utils should do or something the test runner should handle. It's just an idea I had to solve a problem I found a lot while using vue-test-utils.
A number of libraries (for example vee validate, which I have been using heavily in my app) rely on promises. In the case of vee validate, errors are rendered async.
vue-test-utils
does everything sync. Another common test case is asserting some UI changed based on a mock API response, that uses a promise.Both these cases require the test to wait for a promise to resolve (even if it is one that resolves almost immediately).
vue-test-utils
is all sync, I have to use the test runner (in this case jest) to await the promise, or the wrapper.vm is not updated.The below example shows the first case (failing for the reason outlined above) and a workaround.
My original idea was a
triggerAsync
method:However I am starting to think I am heading down the wrong path.
Example:
Component
Test:
https://github.com/lmiller1990/vue-test-utils-async for example using vee-vadidate
Or, am I venturing out of the realm of unit test into e2e test here?
The text was updated successfully, but these errors were encountered: