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

How do you disable animations in tests? #119

Closed
tansongyang opened this issue Jun 3, 2019 · 5 comments
Closed

How do you disable animations in tests? #119

tansongyang opened this issue Jun 3, 2019 · 5 comments

Comments

@tansongyang
Copy link

Having a hard time finding any information about this in the docs. We'd like animations to be completely disabled during tests. How do we do that?

I did find this liquid-fire issure. It recommends that we check config.environment. If 'test', set animation durations to 0.

We've done that, but we still sometimes get random test failures in our code that uses animations. In the end, we resorted to using waitUntil.

@ef4
Copy link
Contributor

ef4 commented Jun 10, 2019

We don't really support completely turning off animations, because that would let you miss a lot of potential failures. It would mean you were testing under unrealistic conditions.

Instead, we give you control over the flow of time as seen by ember-animated, so you can make your animations go as fast or slow as you want to support the test you want to write.

import { 
  setupAnimationTest, 
  time, 
  animationsSettled 
} from 'ember-animated/test-support';

module('Acceptance | something', function(hooks) {
  setupApplicationTest(hooks);
  setupAnimationTest(hooks);

  test('a thing', async function(assert) {
    // run animations 100x faster than normal. If you want this for the whole 
    // test suite, you can say the same thing in `beforeEach`
    time.runAtSpeed(100);
    ...
    // let them finish. They will finish very fast, but not zero time.
    await animationsSettled();
  });

  test('another thing', async function(assert) {
    // take over the clock entirely
    time.pause();
    await click('...');
    time.advance(10); // let the first 10 milliseconds of the animation run
    assert(...); // inspect the state of things at that point in the animation
    // let the rest of the animation finish quickly
    time.runAtSpeed(100);
    await animationsSettled();
    assert(...); // see what the final state of things looks like
  });

});

@tansongyang
Copy link
Author

@ef4, thanks for your response! We weren't aware of animationsSettled; we'll try it out and see how it goes.

@ef4
Copy link
Contributor

ef4 commented Jun 10, 2019

Yeah, we need to document the test helpers better.

@tansongyang
Copy link
Author

Thanks, everyone; I've confirmed that this works for us.

@RobbieTheWagner
Copy link
Contributor

We have a weird bug that in Electron animationsSettled only works the first time it is called per test. Then all the subsequent calls do not wait for the animations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants