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

Split test support into two modes #199

Open
ef4 opened this issue Feb 20, 2020 · 6 comments
Open

Split test support into two modes #199

ef4 opened this issue Feb 20, 2020 · 6 comments

Comments

@ef4
Copy link
Contributor

ef4 commented Feb 20, 2020

Right now we have setupAnimationTest, which is good for when you want to actually assert about animations.

We should add a second test setup function for when you just want the animations to not effect your tests at all. It can do the same runAtSpeed(40) that setupAnimationTest does by default, but it would also use registerWaiter to make Ember settled wait for transitions to finish, so they never affect what your tests are seeing.

@balinterdi
Copy link
Contributor

balinterdi commented Feb 21, 2020

For context, here's my original post on Discuss:
https://discuss.emberjs.com/t/testing-ember-animated-apps/17535/3

If I understand correctly, that other test helper (tentative name: fastForwardAnimationsTest) would be independent of setupAnimationTest. Set up this way, if you, as a developer:

  1. Want to test the actual details of an animation, you'd use setupAnimationTest.
  2. Want to not be bothered by animations, you'd use fastForwardAnimationsTest that would, behind the scenes, call setupAnimationsTest and also set up the registerWaiter you mention above.

Is that correct?

(We'd have to find a better name for fastForwardAnimationsTest unless you like it.)

@Turbo87
Copy link
Contributor

Turbo87 commented May 26, 2020

FWIW I think it would be easiest to not have a dedicated test helper but instead introduce an option in the existing one:

setupAnimationTest(hooks, { waitForAnimations: true });

or something roughly like that

@RobbieTheWagner
Copy link
Contributor

Any progress on this? We have a test suite that all passes in a normal browser environment, but fails when run in Electron, and it seems to be animationsSettled not working in Electron for some reason.

@balinterdi
Copy link
Contributor

I haven't had time to work on this, unfortunately.

@RobbieTheWagner
Copy link
Contributor

Does anyone have any idea why animationsSettled would only work the first time it is used in Electron? Subsequent calls do not wait for the animations and we're forced to add in extra waitUntil calls to manually wait.

@joukevandermaas
Copy link

If anyone else is hitting this issue after scratching their head for a while, this is the solution I came up with. I now use setupWaitForAnimationApplicationTest instead of setupApplicationTest and it makes the regular test helpers wait for animations as well as everything else. I'm not super happy with it, so any suggestions are welcome. At least it solves my problem.

import { waitForPromise } from '@ember/test-waiters';
import { setupApplicationTest } from 'ember-qunit';

const setupWaitForAnimationApplicationTest = function (hooks) {
  setupApplicationTest(hooks);

  const animationObserver = ({ task }) => {
    waitForPromise(task);
  }

  hooks.beforeEach(async function () {
    // register test waiter for animations
    let service = this.owner.lookup('service:-ea-motion');
    service.observeAnimations(animationObserver);
  });

  hooks.afterEach(function () {
    // unregister test waiter for animations
    let service = this.owner.lookup('service:-ea-motion');
    service.unobserveAnimations(animationObserver);
  });
};

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

6 participants