Skip to content

Commit

Permalink
use a spy for callback tests
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed Nov 14, 2015
1 parent 7bdada7 commit a72a2cf
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions test/specs/matchHeight.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('<p>Test content update.</p>');
Expand Down Expand Up @@ -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();
});
Expand Down

0 comments on commit a72a2cf

Please sign in to comment.