Skip to content
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

Request: Velocity mock setting for UI testing #109

Closed
edance opened this issue Jun 13, 2014 · 9 comments
Closed

Request: Velocity mock setting for UI testing #109

edance opened this issue Jun 13, 2014 · 9 comments

Comments

@edance
Copy link

edance commented Jun 13, 2014

I would like to disable all my javascript animations while testing. Is there a way to do this with velocity? Something like $.fx.off?

@julianshapiro
Copy link
Owner

Do you mean you want all Velocity calls to do nothing?

I can't speak on behalf of jQuery itself, but if you want Velocity calls to do nothing, just reassign Velocity to an empty function using $.fn.velocity = function() { return this; };

@edance
Copy link
Author

edance commented Jun 13, 2014

Thanks for your quick reply!

I should have been more clear but basically make it so the duration of all the animations is zero. I am running into an issue where I need to wait for the animation to be completed before continuing to the next step while testing.

@julianshapiro
Copy link
Owner

My pleasure. It's a good Q.

For unit testing animations, I do asynchronous testing with qUnit.

I presume you're doing UI testing, in which case I understand the unique problem you're trying to tackle, and I can't think of a solution off the top of my head. I'd have to hardcode in a feature for doing this directly inside of Velocity, e.g. passing in a flag to tell Velocity you want instantaneous changes.

Can anyone else chime in if they would like this as well? The more +1's I get, the more likely I'll be to implement this.

@julianshapiro julianshapiro changed the title Globally disable all animations Feature: Forcefully set all durations to 1ms for the purposes of UI testing Jun 13, 2014
@ydaniv
Copy link
Contributor

ydaniv commented Jun 13, 2014

@julianshapiro, IMHO either users test it as is using an async testing library like you said or you (or someone) implement a new module - e.g. velocity.mock.js - that will allow this functionality.
Personally, I don't think this functionality should be a part of Velocity.

@Oliboy50
Copy link

In contrary, I think it's could be a great feature. I'm working on a card game using Velocity, and that might be cool enough if I could let the players choose if they want skip all animation or not... It's maybe not a big feature in a card game, but a game containing longer animations... Like the "skip skill animations" in Pokemon, do you see what I mean ?

@julianshapiro
Copy link
Owner

@Oliboy50: For your specific case, just set the animation duration to 0 if the user wants to bypass animations. That's an easy thing for you to check for and pass into Velocity.

@ydaniv: After some testing, it's apparent that it's incredibly convoluted and redundant to extract this into a mock file. In comparison, it'll take 2 lines of code to implement this directly into Velocity.

@edance: So, I've concluded that I'll build this into Velocity. Expect it shortly.

@julianshapiro julianshapiro changed the title Feature: Forcefully set all durations to 1ms for the purposes of UI testing Request: Create a Velocity mock file for the purposes of UI testing Jun 13, 2014
@julianshapiro
Copy link
Owner

@edance:

With the latest version of Velocity, you can now set $.Velocity.mock = true; before running your tests. All animations will thereafter be forced to a duration of 1ms.

Can you please test this out for your purposes and report back to me if this is sufficient and if you have any related requests/suggestions?

@julianshapiro julianshapiro changed the title Request: Create a Velocity mock file for the purposes of UI testing Request: Velocity mock setting for the purposes of UI testing Jun 13, 2014
@edance
Copy link
Author

edance commented Jun 13, 2014

Thanks so much @julianshapiro! I will check it out tonight and let you know. Thanks for making such an awesome product!

@julianshapiro
Copy link
Owner

Thank you for the awesome suggestion :-D @ydaniv was ultimately right, but a compromise had to be made. (I started building out a mock file, but it was ballooning in size due to Velocity's variable arguments syntax.)

@julianshapiro julianshapiro changed the title Request: Velocity mock setting for the purposes of UI testing Request: Velocity mock setting for UI testing Jun 13, 2014
Rycochet pushed a commit that referenced this issue Aug 3, 2020
Mock flag for UI testing.
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

No branches or pull requests

4 participants