Skip to content

Conversation

mark-de-haan
Copy link
Contributor

When an error occurs in an assertion, you receive the message that your promise hook was not closed within 2 seconds.
By catching the error, we can call done(error) (this works for standard vue-cli template)

  1. This makes sure the test is properly closed
  2. The assertion error is logged to the console

When an error occurs in an assertion, you receive the message that your promise hook was not closed within 2 seconds.
By catching the error, we can call done(error) (this works for standard vue-cli template)
1. This makes sure the test is properly closed
2. The assertion error is logged to the console
@posva
Copy link
Member

posva commented May 12, 2017

what test framework are you using? A non-caught exception in the synchronous code should make the test fail

@mark-de-haan
Copy link
Contributor Author

mark-de-haan commented May 12, 2017

Im using Karma + Mocha (from the standard vue init command)
Im testing my actions, and mocked the response of any API calls using testdouble.

I am using the testAction helper function found in the Vuex docs.
In case of expect(1).to.equal(2) inside the the testAction function, you will only get the message that the Promise hook has not been closed.

You will not get the notification that your expected value 1 does not equal 2

I could try-catch the actual method call itself, but seeing as I call the testAction function very often, Id rather have it at the spot where my actual expect assertions are being done.

Though if you think people should be responsible for their own asynch stupidity, I can understand you do not want to catch errors on this level 😋

@posva
Copy link
Member

posva commented May 12, 2017

Aaah, I see. I didn't see there was a helper there calling the mutation in a callback. I prefer not mocking everything when testing actions and dispatch them, this way I get a Promise and I can append .catch(done).

I think that in this case the try/catch is ok 🙂

Copy link
Member

@ktsn ktsn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@ktsn ktsn merged commit 665f60c into vuejs:dev May 14, 2017
ktsn added a commit that referenced this pull request May 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants