From a72a2cf545ea088ebfc0ae93b12fd99daa75919c Mon Sep 17 00:00:00 2001 From: liabru Date: Sat, 14 Nov 2015 23:45:05 +0000 Subject: [PATCH] use a spy for callback tests --- test/specs/matchHeight.spec.js | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/test/specs/matchHeight.spec.js b/test/specs/matchHeight.spec.js index 605f0f0..3148812 100644 --- a/test/specs/matchHeight.spec.js +++ b/test/specs/matchHeight.spec.js @@ -273,21 +273,11 @@ describe('matchHeight', function() { }); it('can manually update heights and fires global callbacks', function(done) { - var currentBreakpoint = testHelper.getCurrentBreakpoint(), - calledBefore = false, - calledAfter = false; + var currentBreakpoint = testHelper.getCurrentBreakpoint(); - var oldBefore = $.fn.matchHeight._beforeUpdate, - oldAfter = $.fn.matchHeight._afterUpdate; - - // set some test update callbacks - $.fn.matchHeight._beforeUpdate = function() { - calledBefore = true; - }; - - $.fn.matchHeight._afterUpdate = function() { - calledAfter = true; - }; + // spy on global callbacks + spyOn($.fn.matchHeight, '_beforeUpdate'); + spyOn($.fn.matchHeight, '_afterUpdate'); // add more content to one of the items to change it's height $('.simple-items .item-1').append('

Test content update.

'); @@ -329,12 +319,15 @@ describe('matchHeight', function() { } // check callbacks were fired - expect(calledBefore).toBe(true); - expect(calledAfter).toBe(true); + expect($.fn.matchHeight._beforeUpdate).toHaveBeenCalled(); + expect($.fn.matchHeight._afterUpdate).toHaveBeenCalled(); + + var beforeUpdateArgs = $.fn.matchHeight._beforeUpdate.calls.argsFor(0), + afterUpdateArgs = $.fn.matchHeight._afterUpdate.calls.argsFor(0); - // revert callbacks - $.fn.matchHeight._beforeUpdate = oldBefore; - $.fn.matchHeight._afterUpdate = oldAfter; + // group arg + expect($.isArray(beforeUpdateArgs[1])).toBe(true); + expect($.isArray(afterUpdateArgs[1])).toBe(true); done(); });