Skip to content

Instantly share code, notes, and snippets.

@eoinkelly
Last active March 9, 2024 13:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eoinkelly/11197960 to your computer and use it in GitHub Desktop.
Save eoinkelly/11197960 to your computer and use it in GitHub Desktop.
Test CSS Animations in Ember with Mocha & Chai
// TODO:
// * work with all browser prefixes for event names
// * make error message more helpful
it('tests that a CSS animation ran correctly', function (done) { // <-- notice the done param
// Visit whatever route we are going to test
visit('/unique_testing_route')
.then(function () {
// CSS Animations do not run unless they are visible (presumably a
// performance thing) so we must make the app visible before running
// this test
showEmber();
// Find the element that the animation will be applied to
var el = find('.item .label')[0];
// Create a listener that will check that the correct animation ran
// and also call done() to let mocha know that the test is finished
var listener = function (e) {
if (e.animationName === 'your-awesome-animation-name' {
done(); // <-- calling done() to tell Mocha we are finished
} else {
throw new Error('Animation had wrong name'); // Explosion!
}
};
// Add our listener to the element
el.addEventListener('webkitAnimationStart', listener, false);
})
.click('.item:first .btn.correct-answer') // trigger the thing that will start the animation
.then(function () {
// Clean up by hiding the ember app again. This could also be done in an afterEach()
hideEmber();
});
});
// spec/helpers.js
function showEmber() {
$('#ember-root').css('display', 'block');
}
function hideEmber() {
$('#ember-root').css('display', 'none');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment