Jump to content
Search Community

mnKH2cnPMAbMq

Members
  • Posts

    1
  • Joined

  • Last visited

Everything posted by mnKH2cnPMAbMq

  1. I know this is an old thread, but it comes up as the first hit in google when trying to figure out ways to unit test around GSAP. Here is a sample unit test of mine, that I use to test code that uses GSAP: var $ = require('jquery'); var _ = require('underscore'); var rewire = require('rewire'); var reviewAnimations = rewire('src/animations/reviewAnimations.js'); var stubbedTimeline = { play : function() { }, fromTo : function(a, b, c, d) { if (_.isEqual(d , {"opacity":1,"scale":1,"ease":"Back.easeOut"})) { passed = true; } } }; var myTimelineLite = function() {return stubbedTimeline;} var passed = false; describe('review animations tester', function() { it('set the opacity of the div', function() { var div = $('<div style="opacity:0"></div>'); expect(div.css('opacity')).to.equal('0'); var restore = reviewAnimations.__set__("TimelineLite", myTimelineLite); reviewAnimations.checkmark(div); expect(passed).to.equal(true); restore(); }); }); Here I'm testing reviewAnimations.js. What I've done is I replaced TimeLineLite in the file I'm testing with a stubbed out version. If I didn't want to stub every call the original file uses I could have used sinon.stub on a real TimeLineLite before using rewire to inject my fake TimeLineLite into the original file. This works pretty well and has the nice side effect of keeping GSAP from running when my unit tests run. Thanks, Joseph Elwell.
×
×
  • Create New...