Skip to content

Commit a72a2cf

Browse files
committed
use a spy for callback tests
1 parent 7bdada7 commit a72a2cf

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

test/specs/matchHeight.spec.js

+12-19
Original file line numberDiff line numberDiff line change
@@ -273,21 +273,11 @@ describe('matchHeight', function() {
273273
});
274274

275275
it('can manually update heights and fires global callbacks', function(done) {
276-
var currentBreakpoint = testHelper.getCurrentBreakpoint(),
277-
calledBefore = false,
278-
calledAfter = false;
276+
var currentBreakpoint = testHelper.getCurrentBreakpoint();
279277

280-
var oldBefore = $.fn.matchHeight._beforeUpdate,
281-
oldAfter = $.fn.matchHeight._afterUpdate;
282-
283-
// set some test update callbacks
284-
$.fn.matchHeight._beforeUpdate = function() {
285-
calledBefore = true;
286-
};
287-
288-
$.fn.matchHeight._afterUpdate = function() {
289-
calledAfter = true;
290-
};
278+
// spy on global callbacks
279+
spyOn($.fn.matchHeight, '_beforeUpdate');
280+
spyOn($.fn.matchHeight, '_afterUpdate');
291281

292282
// add more content to one of the items to change it's height
293283
$('.simple-items .item-1').append('<p>Test content update.</p>');
@@ -329,12 +319,15 @@ describe('matchHeight', function() {
329319
}
330320

331321
// check callbacks were fired
332-
expect(calledBefore).toBe(true);
333-
expect(calledAfter).toBe(true);
322+
expect($.fn.matchHeight._beforeUpdate).toHaveBeenCalled();
323+
expect($.fn.matchHeight._afterUpdate).toHaveBeenCalled();
324+
325+
var beforeUpdateArgs = $.fn.matchHeight._beforeUpdate.calls.argsFor(0),
326+
afterUpdateArgs = $.fn.matchHeight._afterUpdate.calls.argsFor(0);
334327

335-
// revert callbacks
336-
$.fn.matchHeight._beforeUpdate = oldBefore;
337-
$.fn.matchHeight._afterUpdate = oldAfter;
328+
// group arg
329+
expect($.isArray(beforeUpdateArgs[1])).toBe(true);
330+
expect($.isArray(afterUpdateArgs[1])).toBe(true);
338331

339332
done();
340333
});

0 commit comments

Comments
 (0)